[英]Qt executable running in release folder - Runtime error in Program Files (x86)
I seem to be getting a runtime error when trying to run my Qt application. 尝试运行Qt应用程序时,似乎出现运行时错误。
I am able to successfully build my application in release mode and it runs just fine sitting in the release folder. 我能够在发布模式下成功构建我的应用程序,并且它可以在发布文件夹中正常运行。 That's not where it's going to sit when users install it, however.
但是,当用户安装它时,它并不会位于其中。 I need it to run in
C:/Program Files (x86)/ApplicationName/application.exe
. 我需要它在
C:/Program Files (x86)/ApplicationName/application.exe
。
So I moved the application there. 所以我将应用程序移到了那里。 I recently added some
SQLite
functionality to the application. 我最近向该应用程序添加了一些
SQLite
功能。 So I expected to get some sort of missing dll file error. 因此,我希望得到某种丢失的dll文件错误。 I did.
是的 So I found the correct dll file (
Qt5Sql.dll
) and moved it into that directory. 因此,我找到了正确的dll文件(
Qt5Sql.dll
)并将其移至该目录。 Now I'm getting a Runtime Error. 现在,我遇到了运行时错误。
To figure out what was causing this Runtime Error, I threw in a bunch of QMessageBox::warning
s to see when it was getting the error. 为了弄清楚是什么原因导致了运行时错误,我投入了一堆
QMessageBox::warning
来查看它何时得到错误。 The error is being caused by this line of code: 该错误是由以下代码行引起的:
sqlite = new SQLite(QString("%1%2").arg(myDocuments).arg(SQLite::DATABASE_NAME));
I checked to make sure I was getting the expected QString
from QString("%1%2").arg(myDocuments).arg(SQLite::DATABASE_NAME)
and I was. 我检查以确保我从
QString("%1%2").arg(myDocuments).arg(SQLite::DATABASE_NAME)
中获得了预期的QString
。
Here is what that constructor looks like in sqlite.cpp
: 这是
sqlite.cpp
中的构造函数的样子:
SQLite::SQLite(const QString& path)
{
database = QSqlDatabase::addDatabase("QSQLITE");
database.setDatabaseName(path);
if (!database.open())
{
QMessageBox::warning(NULL, "Error", "Failed to open database.");
}
}
The peculiar thing is I know I'm not even getting into that constructor because I put a QMessageBox::warning
before the first line in the constructor and I'm not seeing that before the Runtime Error. 奇怪的是,我知道我什至没有进入那个构造函数,因为我在构造函数的第一行之前放置了
QMessageBox::warning
,而在运行时错误之前看不到它。 I am seeing the QMessageBox::warning
directly before the constructor though. 我在构造器之前直接看到
QMessageBox::warning
。
Anyone out there have any idea what might be causing this? 外面有人知道是什么原因造成的吗?
Edit: 编辑:
I believe I was missing the sqldriver
folder which included the qsqlite.dll
. 我相信我缺少包含
qsqlite.dll
的sqldriver
文件夹。 I added that folder to where my exe
file is, but I'm still getting a runtime error. 我将该文件夹添加到我的
exe
文件所在的位置,但是仍然遇到运行时错误。 I added the following to my code for debugging purposes: 我在代码中添加了以下内容以进行调试:
QStringList drivers = QSqlDatabase::drivers();
QString ds;
int len = drivers.length();
for (int x = 0; x < len; x++)
{
ds.append(QString("%1\n").arg(drivers[x]));
}
QMessageBox::warning(this, "DRIVERS", ds);
sqlite = new SQLite(QString("%1%2").arg(myDocuments).arg(SQLite::DATABASE_NAME));
The QMessageBox
shows: QMessageBox
显示:
QSQLITE
QODBC
QODBC3
QPSQL
QPSQL7
After I click OK on the dialog, however, I am still getting the runtime error. 但是,在对话框上单击“确定”后,仍然出现运行时错误。 Despite the
QSQLITE
driver clearly being available, I'm getting the runtime error on this line of code: 尽管
QSQLITE
驱动程序显然可用,但我在以下代码行中遇到了运行时错误:
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
为了简化您的生活,如果您使用的是Qt 5的最新版本,则可以在应用程序上使用windeployqt将依赖项拉到正确的位置。
After much hair pulling I figured out the issue. 经过多拉头发,我弄清楚了这个问题。 It seems one of the
Qt5*
dlls I was using was outdated. 看来我使用的
Qt5*
dll之一已过时。 I saw this error when I moved the dll files from C:/Program Files...
to my release folder and tried running a release version from QtCreator
: 当我将dll文件从
C:/Program Files...
移到我的发布文件夹并尝试从QtCreator
运行发布版本时,我看到了此错误:
Cannot mix incompatible Qt library (version 0x50100) with this library (version 0x50101)
After seeing this, I updated all the Qt5*
dll files in my C:/Program Files (x86)/ApplicationName/
directory and that fixed the problem. 看到此信息后,我更新了
C:/Program Files (x86)/ApplicationName/
目录中的所有Qt5*
dll文件,从而解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.