简体   繁体   English

Qt5 应用程序不运行

[英]Qt5 Application Does Not Run

I created an application using Qt 5 (compiled with Visual Studio '12).我使用 Qt 5(使用 Visual Studio '12 编译)创建了一个应用程序。 It works on my machine.它适用于我的机器。

However, it doesn't work when I attempt to run it on another machine.但是,当我尝试在另一台机器上运行它时它不起作用。 The output I collected through cmd yielded an empty file.我通过 cmd 收集的输出产生了一个空文件。

The directory structure is as follows:目录结构如下:

  • myapp.exe我的应用程序
  • icudt52.dll icudt52.dll
  • icuin52.dll icuin52.dll
  • icuuc52.dll icuuc52.dll
  • libEGL.dll库文件
  • libGLESv2.dll libGLESv2.dll
  • msvcp120.dll msvcp120.dll
  • msvcr120.dll msvcr120.dll
  • Qt5Core.dll Qt5Core.dll
  • Qt5Gui.dll Qt5Gui.dll
  • platforms/qminimal.dll平台/qminimal.dll
  • platforms/qwindows.dll平台/qwindows.dll

The most relevant post I found was Application deployed with QT5 libraries does not start on Windows 7 - yet the solution (including qwindows.dll & qminimal.dll) didn't work.我发现的最相关的帖子是使用 QT5 库部署的应用程序未在 Windows 7 上启动- 但解决方案(包括 qwindows.dll 和 qminimal.dll)不起作用。

Any ideas?有任何想法吗?

Windows will report a number of launch errors just when you double click on your exe outside Qt Creator.当您在 Qt Creator 外双击您的 exe 时,Windows 将报告一些启动错误。 It looks like you have included most or all of these already.看起来您已经包含了大部分或全部这些内容。

Your development machine typically will not have problems launching and running its qt plugins because of the LibraryPaths that are searched by your exe.由于您的 exe 搜索的LibraryPaths ,您的开发机器通常不会在启动和运行其 qt 插件时遇到问题。 http://qt-project.org/doc/qt-5/qcoreapplication.html#libraryPaths http://qt-project.org/doc/qt-5/qcoreapplication.html#libraryPaths

Dependency Walker will do the job and show you what you need to know, but the output is pretty complex and can be hard to decipher. Dependency Walker将完成这项工作并向您展示您需要知道的内容,但输出非常复杂且难以破译。

The easiest way I have found to figure out what Qt plugin dlls I am using at runtime on Windows is to do the following:我发现找出我在 Windows 上运行时使用的 Qt 插件 dll 的最简单方法是执行以下操作:

  1. Exit Qt Creator.退出 Qt Creator。

  2. Open the install folder for the compiler you are using with Qt in Explorer.在资源管理器中打开与 Qt 一起使用的编译器的安装文件夹。 For example:例如:

     C:/Qt/5.3/msvc2010_opengl/
  3. Create a copy of the plugins folder in place ( Copy of plugins folder in the same path as plugins , so its parent is msvc2010_opengl in this case).创建副本plugins (代替文件夹Copy of plugins文件夹中的相同路径plugins ,所以它的母公司是msvc2010_opengl在这种情况下)。

在此处输入图片说明

  1. In another explorer window, open your exe (Qt program) on your development machine.在另一个资源管理器窗口中,在您的开发机器上打开您的 exe(Qt 程序)。 Run a minimal test of your program to make sure the major features are working.对您的程序进行最少的测试,以确保主要功能正常工作。 (Many runtime plugins don't get loaded until QObjects that use them are instantiated). (许多运行时插件在使用它们的 QObject 被实例化之前不会被加载)。

  2. Delete the plugins folder in the Qt path.删除Qt路径下的plugins文件夹。

  3. Windows will lock up all the dlls that are in use by your exe and prevent you from deleting a number of dlls. Windows 将锁定您的 exe 正在使用的所有 dll,并防止您删除许多 dll。 Click skip for all the un-deletable folders and files.单击跳过所有不可删除的文件夹和文件。

在此处输入图片说明

  1. Now go into each of the folders that you couldn't delete before and try to delete all the individual dll's in each folder.现在进入您以前无法删除的每个文件夹,并尝试删除每个文件夹中的所有单独的 dll。 Click skip for all the un-deletable dlls.单击跳过所有不可删除的 dll。

  2. Now when you are all done, you are left with a skeleton of a plugins folder, only showing dlls that your application is using.现在,当您完成所有操作后,您将获得一个插件文件夹的框架,仅显示您的应用程序正在使用的 dll。

  3. It will probably include the folders: accessibility , platforms and imageformats and more depending on what you included in your .pro file.它可能包括以下文件夹: accessibilityplatformsimageformats ,具体取决于您在.pro文件中包含的内容。

  4. Close your exe.关闭你的exe。

  5. Copy the contents of your stripped down plugins folder to sit right next to your exe.将精简后的插件文件夹的内容复制到您的 exe 旁边。

  6. Restore your backup of the plugins folder (delete the stripped down plugins folder from your Qt path and restore the Copy of plugins ).恢复插件文件夹的备份(从 Qt 路径中删除精简的插件文件夹并恢复Copy of plugins )。

  7. Now you should be good to go.现在你应该可以走了。 Test on a non-development machine.在非开发机器上测试。

A Note on VS C++ Runtimes关于 VS C++ 运行时的说明

Also on some machines when deploying Qt with MSVC, the msvcrXXX.dll doesn't match what the rest of the system is using.同样在某些机器上,当使用 MSVC 部署 Qt 时,msvcrXXX.dll 与系统其余部分使用的不匹配。 Instead of deploying msvcrXXX.dll, instead in our installers at our office, we include the Microsoft C++ Redistributable Installer and run it in the install script.我们没有在办公室的安装程序中部署 msvcrXXX.dll,而是包含 Microsoft C++ Redistributable Installer 并在安装脚本中运行它。 And on a few machines they had corrupted Redistributables, and we had to do a force install of redistributables to fix the `Referral from server' error we would sometimes get.在一些机器上,他们损坏了 Redistributables,我们不得不强制安装 Redistributables 以修复我们有时会遇到的“来自服务器的推荐”错误。

You can find the latest installer for MSVC Redistributables here Latest Supported Visual C++ Downloads .您可以在最新支持的 Visual C++ 下载 中找到 MSVC Redistributables 的最新安装程序。

Hope that helps.希望有帮助。

You have to deploy your application before copying dll files manually.您必须在手动复制 dll 文件之前部署您的应用程序。

To deploy your Qt application on Windows you can use windeployqt which can be found in:要在 Windows 上部署 Qt 应用程序,您可以使用windeployqt ,它可以在以下位置找到:

< QTDIR >/bin/windeployqt <QTDIR>/bin/windeployqt

Example batch script may work on deploying your Qt Application (run with PowerShell or cmd):示例批处理脚本可用于部署 Qt 应用程序(使用 PowerShell 或 cmd 运行):

C:\Qt\Qt5.x.x\5.x.x\MSVCx_x\bin\windeployqt <APP_PATH>/myapp.exe
  1. After deploying your app, try to run your myapp.exe and note which dll files are missing.部署应用程序后,尝试运行myapp.exe并注意缺少哪些 dll 文件。

  2. Copy / paste required dll files from QTDIR/bin to your < APP_PATH >将所需的 dll 文件从QTDIR/bin复制/粘贴到您的 <APP_PATH>

for more information about deploying:有关部署的更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM