38

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).

Deploying Qt4 apps on Windows was easy:

  1. You compiled it in release mode.
  2. You copied the necessary libraries (DLLs).
  3. You tested and it worked.

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.

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.

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

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

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

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

Application information:

  • Written and compiled with Qt 5.2.1
  • Uses Quick/QML.
  • Uses the network module.
  • Uses the webkit module.
  • Uses the bluetooth module.
  • The QML files are written in Quick 2.2
Community
  • 1
  • 1
Alex Spataru
  • 1,197
  • 4
  • 14
  • 26
  • What's the exact error? Do you get a crash dump? Did you try to analyze said crash dump in some way? – Michael Kohne Mar 04 '14 at 02:57
  • 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. – Alex Spataru Mar 04 '14 at 03:49
  • 1
    The exact error is "Second chance exception 0xC0000005 (Access Violation) occurred in "QT5GUI.DLL" at address 0x61C2C000." – Alex Spataru Mar 04 '14 at 04:00
  • you won't get a crash if you've missed a dll to deploy. Access violation is a program error. Something is calling into QtGui in the wrong way. Can you not attach a debugger and see - or build with symbols and get a post-mortem crashdump? – gbjbaanb Mar 04 '14 at 18:16
  • http://qt-project.org/forums/viewthread/25714 – gbjbaanb Mar 04 '14 at 18:18
  • I debugged the program and it did not have any errors. After a bit of researching, I found out that I need to copy the "qml" folder (C:/Qt/5.2.1/qml) to the applications root directory. After doing so, both the dynamic and static versions of my application worked. – Alex Spataru Mar 05 '14 at 04:46
  • 2
    It's really sucks honestly. Why can't just they make a Deploy button and be done with it. – GeneCode Sep 14 '17 at 01:25
  • 1
    it absolutely does, @GeneCode . That's why the OP called it "easy", since the "necessary DLLs to copy" any 3-year-old can tell you all about ;-) – dotbit Jan 06 '20 at 21:19
  • 2
    After 5 years have gone by, in 2020 , deploying a trivial Qt App only became worse of a nightmare. – dotbit Jan 06 '20 at 21:26

2 Answers2

40

Starting from Qt 5.2, there is windeployqt tool you can use. Just run it from command line to get help. But basic usage is, give it the .exe file, it will copy Qt dependencies to go with it.

You will want to use --qmldir option to let the tool know where your QML files are, so it can figure out the needed QML dependencies.

Note about testing: to make sure you have everything, test in computer with no Qt SDK, or temporarily rename the Qt directory. Otherwise the application might find missing files from there...

hyde
  • 60,639
  • 21
  • 115
  • 176
  • 3
    I used this tool to deploy my dynamic application, and, as you said, it had problems with the QML folders. To solve it, I just copied the folders inside the /5.2.1/qml. The deployed app worked on systems without the Qt SDK installed. – Alex Spataru Mar 07 '14 at 17:33
  • 6
    My `windeployqt.exe` v5.7.0 missed three dependencies for my 32-bit binary: `libgcc_s_dw2-1.dll`, `libstdc++-6.dll` and `libwinpthread-1.dll`. Had to add them manually from `\Qt\5.7\mingw53_32\bin`. – Neurotransmitter Sep 22 '16 at 20:52
  • '''windeployqt''' does not work as advertised here either, if at all. Probably people should stick with Linux in order to keep stuff working. – dotbit Jan 06 '20 at 21:22
  • @dotbit `windeployqt` is a helper tool, you still need to know what you are doing. And deploying on "Linux" is certainly not any easier, you still need to know what you are doing (especially so if you need to support multiple different distros). – hyde Jan 06 '20 at 22:43
  • @dotbit Basic tools for Windows installer creation (including just a folder you can zip and unzip) are Dependency Walker (for explicit staticalky defined DLL dependencies) and Process Explorer (for plugins and similar things) or similar, there are some options. If you are not familiar with them, look them up. – hyde Jan 06 '20 at 23:30
  • 1
    example where mapviewer is my root dir source code: windeployqt --qmldir C:\Users\ADMIN\Documents\workspace\map\mapviewer qml_location_mapviewer.exe – nobjta_9x_tq May 16 '20 at 10:42
22

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.


Program directory (MinGW 4.8 32-bit, dynamic):

As hyde said, use the windeployqt tool (<qt path>\<version>\bin\windeployqt.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:

  • platforms (folder)
  • QtQuick (folder)
  • QtQuick.2 (folder)
  • Any other QML components that you need
  • 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

Program directory (static)

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 (folder)
  • QtQuick.2 (folder)
  • Any other QML components that you need
  • app.exe

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).

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Alex Spataru
  • 1,197
  • 4
  • 14
  • 26
  • 1
    for the static version: shouldn't it be possible to include the needed qml files in your .exe-file? – bobbaluba May 11 '14 at 09:42
  • I also had to copy C:\Windows\System32\msvcr110d.dll and C:\Windows\System32\msvcp110d.dll to make deployment work for a debug build. (Not necessary for release build, but adding this comment in case anyone wandering across this is trying to deploy a debug build to a system without the debug runtime installed.) – wrdieter Jan 01 '15 at 15:49
  • 2
    *"I found out that I need to copy the "qml" folder"* Did you try the `--qmldir` option instead ? – Ilya Mar 19 '16 at 09:37
  • Newer version like Qt5.7, `qml` path is like `\5.7\msvc2013\qml`. – zhm Oct 24 '16 at 14:05
  • in short: it will take you 48 hours minimum to deploy even a trival hello-win-horror-world App since it is a black art which may work or break, depending on the moon's phase. – dotbit Jan 06 '20 at 21:24