简体   繁体   English

Qt可执行文件在发行文件夹中运行-程序文件(x86)中的运行时错误

[英]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.dllsqldriver文件夹。 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.

相关问题 给定正确的运行时库,x86可执行文件可以在任何x86平台上运行吗? - Can an x86 executable run on any x86 platform given the right runtime libraries? C++ | 如何删除位于 (C:\Program Files (x86)) 的文件夹中的文件 - C++ | How can i delete files in a folder located in (C:\Program Files (x86)) 如何从32位WOW进程获取Program Files文件夹路径(不是Program Files(x86))? - How to get Program Files folder path (not Program Files (x86)) from 32bit WOW process? 吉普错误! 堆栈错误:`C:\\Program Files (x86)\\MSBuild\\12.0\\bin\\msbuild.exe` 失败,退出代码:1 - gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1 在Windows中是否有一个简单的C ++程序文件/程序文件(x86)指令? - Is there a simple Program Files/Program Files (x86) directive for C++ in windows? Qt 所有功能都可以在发布文件夹中使用,但不能在程序文件中使用 - Qt. All functions work in release folder, but not in Program Files 为什么编译64位程序时CMake默认为Program Files x86? - Why does CMake default to Program Files x86 when compiling 64 bit program? 我在笔记本电脑上找不到文件夹C:\\ Program Files(x86)\\ Microsoft Visual Studio 14.0 \\ VC \\ include \\ gl。 如何添加? - I cannot find the folder C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\gl on my laptop. How do I add it? 复制到程序文件(x86)时无法执行我的DLL - Cannot execute my DLL when copied to Program Files (x86) 为什么 FOLDERID_ProgramFiles 返回“C:\\Program Files (x86)”? - Why does FOLDERID_ProgramFiles return “C:\Program Files (x86)”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM