在 Windows 上部署 Qt 5 应用程序

时间:2022-10-18
本文介绍了在 Windows 上部署 Qt 5 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我用 QML(Qt 5 的一部分)编写了几个应用程序.在我之前提出的一个问题中 (https://softwareengineering.stackexchange.com/questions/213698/deploying-qt-based-app-on-mac-os-x),我找到了在 OS X 上部署我的应用程序的解决方案(使用 macdeployqt 工具).

I've written a couple of applications in QML (part of Qt 5). In a question that I've made before (https://softwareengineering.stackexchange.com/questions/213698/deploying-qt-based-app-on-mac-os-x), I found the solution for deploying my app on OS X (using the macdeployqt tool).

在 Windows 上部署 Qt4 应用程序很容易:

Deploying Qt4 apps on Windows was easy:

  1. 您在发布模式下编译它.
  2. 您复制了必要的库 (DLL).
  3. 您进行了测试,效果很好.

不幸的是,这种方法在 Qt5 中不起作用(我什至在 qwindows.dll 文件中包含了平台文件夹,但它不起作用).经过几天的尝试,我放弃并编译了一个静态版本的Qt5.

Unfortunately, this approach did not work in Qt5 (I even included the platforms folder with the qwindows.dll file and it did not work). After some days of trying, I gave up and compiled a static version of Qt5.

同样,它不起作用.该应用程序可在安装了 Qt 的 PC 上运行,但在干净"的 PC 上会崩溃.作为旁注,Windows 8/8.1 系统不会发出警告或消息通知我有关应用程序崩溃的信息.但是在 Windows 7 中,一条消息通知我应用程序崩溃了.

Again, it did not work. The app works on a PC with Qt installed, but it crashes on "clean" PCs. As a side note, Windows 8/8.1 systems don't give a warning or a message notifying me about the app's crash. But in Windows 7 a message notifies me that the application crashed.

我试过运行 Dependency Walker (depends.exe),我的应用程序静态构建中的所有库看起来都很好.

I've tried running Dependency Walker (depends.exe) and all libraries in the static build of my application seemed fine.

在 Windows 8 中,我没有收到任何错误.但是在depends.exe 中分析应用程序后,我收到了来自QtGui.dll 的访问冲突.确切的错误是

In Windows 8, I don't get any error. But after profiling the app in depends.exe, I get an access violation originating from QtGui.dll. The exact error is

在地址 0x61C2C000 的QT5GUI.DLL"中发生第二次机会异常 0xC0000005(访问冲突).

Second chance exception 0xC0000005 (Access Violation) occurred in "QT5GUI.DLL" at address 0x61C2C000.

有什么我遗漏的吗(比如一个额外的 DLL 或配置文件)?

Is there something that I am missing (say an extra DLL or config file)?

申请信息:

  • 使用 Qt 5.2.1 编写和编译
  • 使用 Quick/QML.
  • 使用网络模块.
  • 使用 webkit 模块.
  • 使用蓝牙模块.
  • QML 文件是用 Quick 2.2 编写的

推荐答案

在 Qt 论坛中挖掘了几个小时后,我发现我需要复制qml"文件夹(通常位于 C:/Qt/5.2.1/qml) 到应用程序的根目录.这样做之后,我的应用程序的动态和静态版本都可以在普通系统上运行.

After some hours digging in the Qt Forums, I found out that I need to copy the "qml" folder (normally located in C:/Qt/5.2.1/qml) to the application's root directory. After doing so, both the dynamic and static versions of my application worked on vanilla systems.

程序目录(MinGW 4.8 32 位,动态):

正如 hyde 所说,使用 windeployqt 工具(;inwindeployqt.exe) 将必要的文件复制到应用程序的文件夹中.之后,将所需的 QML 组件从 qml 复制到您的应用程序文件夹.生成的文件夹应类似于:

As hyde said, use the windeployqt tool (<qt path><version>inwindeployqt.exe) to copy the necessary files to your application's folder. After that, copy the required QML components from <qt path><version>qml to your application's folder. The resulting folder should look similar to:

  • 平台(文件夹)
  • QtQuick(文件夹)
  • QtQuick.2(文件夹)
  • 您需要的任何其他 QML 组件
  • app.exe
  • icudt51.dll
  • icuin51.dll
  • icuuc51.dll
  • libgcc_s_dw2-1.dll
  • libstdc++-6.dll
  • libwindthread-1.dll
  • Qt5Core.dll
  • Qt5Gui.dll
  • Qt5Qml.dll
  • Qt5Quick.dll
  • Qt5Network.dll
  • Qt5Widgets.dll

程序目录(静态)

静态编译应用程序,然后将所需的 QML 组件从 qml 复制到应用程序的文件夹中.生成的文件夹应类似于:

Compile the application statically, then copy the required QML components from <qt path><version>qml to your application's folder. The resulting folder should look similar to:

  • QtQuick(文件夹)
  • QtQuick.2(文件夹)
  • 您需要的任何其他 QML 组件
  • app.exe

我认为崩溃的原因是 Qt5Gui.dll(动态和静态)在运行时尝试"加载 QtQuick* 文件夹,但找不到它们(因此崩溃了加载期间的应用程序).

I think the cause for the crash was that the Qt5Gui.dll (dynamic and static) "tried" to load the QtQuick* folders during run time, but could not find them (thus crashing the application during load).

这篇关于在 Windows 上部署 Qt 5 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一条:是否有适用于 Windows (Visual C) 的 unistd.h 的替代品? 下一条:如何在 Windows 上使线程休眠少于一毫秒

相关文章

最新文章