Qt5 Application Does Not Run

十年热恋 提交于 2021-02-07 20:23:42

问题


I created an application using Qt 5 (compiled with 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.

The directory structure is as follows:

  • myapp.exe
  • icudt52.dll
  • icuin52.dll
  • icuuc52.dll
  • libEGL.dll
  • libGLESv2.dll
  • msvcp120.dll
  • msvcr120.dll
  • Qt5Core.dll
  • Qt5Gui.dll
  • platforms/qminimal.dll
  • platforms/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.

Any ideas?


回答1:


Windows will report a number of launch errors just when you double click on your exe outside Qt Creator. 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. 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.

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:

  1. Exit Qt Creator.

  2. Open the install folder for the compiler you are using with Qt in Explorer. 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).

enter image description here

  1. In another explorer window, open your exe (Qt program) on your development machine. 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).

  2. Delete the plugins folder in the Qt path.

  3. Windows will lock up all the dlls that are in use by your exe and prevent you from deleting a number of dlls. Click skip for all the un-deletable folders and files.

enter image description here

  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. Click skip for all the un-deletable dlls.

  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.

  3. It will probably include the folders: accessibility, platforms and imageformats and more depending on what you included in your .pro file.

  4. Close your exe.

  5. Copy the contents of your stripped down plugins folder to sit right next to your 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).

  7. Now you should be good to go. Test on a non-development machine.

A Note on VS C++ Runtimes

Also on some machines when deploying Qt with MSVC, the msvcrXXX.dll doesn't match what the rest of the system is using. 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. 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.

You can find the latest installer for MSVC Redistributables here Latest Supported Visual C++ Downloads.

Hope that helps.




回答2:


You have to deploy your application before copying dll files manually.

To deploy your Qt application on Windows you can use windeployqt which can be found in:

< QTDIR >/bin/windeployqt

Example batch script may work on deploying your Qt Application (run with PowerShell or 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.

  2. Copy / paste required dll files from QTDIR/bin to your < APP_PATH >

for more information about deploying:

  • Windows Deploying Tool - windeployqt
  • Deploying on Windows


来源:https://stackoverflow.com/questions/26387445/qt5-application-does-not-run

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!