Deploy Qt5 QML Application

To test the deployment of QML, I created a very simple QML application. Here is the code:

main.cpp

#include <QApplication> #include <QQmlApplicationEngine> #include <QFile> int main(int argc, char **argv) { QApplication app(argc, argv); QQmlApplicationEngine engine; QString path = app.applicationDirPath() + "/qml/main.qml"; if(QFile::exists(path)) engine.load(path); else { return 1; } return app.exec(); } 

main.qml

 import QtQuick 2.2 import QtQuick.Controls 1.2 ApplicationWindow { id: mainWindow title: "Test window" width: 800 height: 600 visible: true } 

To make sure that the development library is not installed on the system, I set up a virtual machine with a clean installation of Windows XP. Then I followed the instructions described here and copied all Qt5 * .dll to the program directory, as well as the /qwindows.dll and icu * 52.dll platforms. Dependency Walker confirmed that there were no broken dependencies, i.e. Everything must be properly configured.

However, for some reason, when I run my application, I see nothing. Neither a window nor an error message. Running from the console also gives me no error. Despite this, I see that my application is running in the task manager, for example, running in the background. Running the application on the development machine goes without problems: the application starts correctly, and I see its windows.

What am I doing wrong? How can I deploy a QML application to make sure that it will work on any other machine without development?

+11
source share
5 answers

If you use MinGW, try copying all the folders from the qml folders and plugins to the directory with your program. Also copy the libraries: icudt52.dll , icuin52.dll , icuuc52.dll , libgcc_s_dw2-1.dll , libstdc++-6.dll , libwinpthread-1.dll , Qt5Core.dll , Qt5Gui.dll , Qt5Network.dll , Qt5Qml.dll , Qt5Quick.dll , Qt5Svg.dll , Qt5Widgets.dll from bin

In the end, the directory will look like this:

  • Enginio
  • imageformats
  • platforms
  • Qt
  • QtGraphicalEffects
  • QtPositioning
  • QtQml
  • QtQuick
  • QtQuick.2
  • QtSensors
  • QtWebKit
  • QtWinExtras
  • icudt52.dll
  • icuin52.dll
  • icuuc52.dll
  • libgcc_s_dw2-1.dll
  • libstdc ++ - 6.dll
  • libwinpthread-1.dll
  • Qt5Core.dll
  • Qt5Gui.dll
  • Qt5Network.dll
  • Qt5Qml.dll
  • Qt5Quick.dll
  • Qt5Svg.dll
  • Qt5Widgets.dll
  • YOUR_PROGRAM.exe

This method works on WindowsXP / Win7, where Qt has not been installed.

+8
source

This is what I have guessed so far,

You cannot just open the qml file in main.cpp, you have to put these qmls in the resource

qml.qrc:

 <RCC> <qresource prefix="/"> <file>main.qml</file> </qresource> </RCC> 

Then main.cpp should load it from a resource

 int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); } 

then build and see if it works, then expand it like this:

  • find the release directory where your exe resides
  • find the directory where your QML lives
  • create a directory somewhere, say deploy

then

 cd deploy windeployqt --release --qmldir <qml-dir-location> <exe-location> 

NOTE: add the windeployqt location to PATH for example. C: \ Qt \ Qt5.5.1 \ 5.5 \ msvc2013 \ BIN

+5
source

You should use the deployment tool that comes with Qt. See Qt for Windows - Deployment , there is a "Windows Deployment Tool" section.

+2
source

You need to deploy the application, for this I use the cqtdeployer utility

This utility itself collects all the necessary dependencies of your application, and you do not need to spend your time on this, or you can automate this process.

You can install from github releases (Windows)

or

from a snap (Linux)

 sudo snap install cqtdeployer 

You can use as follows:

  • Window:
 %cqtdeployer% -bin myApp -qmake path/to/Qt/5.xx/build/bin/qmake.exe -qmlDir path/to/my/qml/files/dir 
  • Linux:
 cqtdeployer -bin myApp -qmake path/to/Qt/5.xx/build/bin/qmake -qmlDir path/to/my/qml/files/dir 
  • path / to / Qt / 5.xx / build / bin / qmake is the way qmake is used to build your program.

  • path / to / my / qml / files / dir is the path directly to your qml file (which you wrote)

And run the application using the script sh (Linux) or exe (Windows)

If you will use the snap-in version, make sure that you have all permissions. cqtdeployer

If you need to use a version of Windows, just install the application from the installer

0
source

As BaCaRoZzo mentioned, the general solution that I really liked was to follow this guide .

To summarize, copy to an empty directory:

  • The release version of MyApp.exe, as well as the .dll that you created for this project
  • All .dll files from \ mingw48_32 \ bin \
  • All folders from \ mingw48_32 \ plugins \
  • (If you used QML) All folders from \ mingw48_32 \ qml \

First, while testing the application, rename the qt folder so that it is not found by $ PATH, and double-click MyApp.exe. This should start the program.

NB. This leads to a very large application, so you will need to delete some additional files and folders. The easiest way to dll: you run the program, and while you work, you delete all the dll in your new project. Only those that are not used by MyApp.exe will be deleted. Effective!
For Qt folders, use the trial and error method.

0
source

Source: https://habr.com/ru/post/973138/


All Articles