Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Qt 5 App on Windows

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
like image 552
Alex Spataru Avatar asked Mar 04 '14 01:03

Alex Spataru


People also ask

How do I deploy a Qt application in Windows?

To deploy the application, we must make sure that we copy the relevant Qt DLLs (corresponding to the Qt modules used in the application) and the Windows platform plugin, qwindows. dll , as well as the executable to the same directory tree in the release subdirectory.

Can Qt apps run on Windows?

Yes. The code that you write using Qt will work on Windows, Mac, Linux/X11, embedded Linux, Windows CE and Symbian without any change.


2 Answers

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

like image 115
hyde Avatar answered Sep 18 '22 15:09

hyde


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

like image 20
Alex Spataru Avatar answered Sep 19 '22 15:09

Alex Spataru