Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Qt5 QML application

To test QML deployment I've 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 be sure no development library was installed in the system, I've set up a virtual machine with a pure Windows XP installation. Then, I've followed instructions as described here and copied all Qt5*.dll into the program directory, as well as platforms/qwindows.dll and icu*52.dll. Dependency Walker confirmed that no broken dependencies were left, i.e. everything should have been correctly set up.

However, for some reasons, when I run my app I see nothing. Neither a window, nor an error message. Running from console also gives me no error. Despite this, I can see my app running in the Task manager, like it is running in background. Running the app on the development machine goes without problem: the app correctly starts and I can see its windows.

What am I doing wrong? How can I deploy a QML app to be sure it will work on any other - non development - machine?

like image 252
folibis Avatar asked Jul 31 '14 00:07

folibis


4 Answers

This what i've figured out so far,

You can't just open a qml file in main.cpp, you have to put those qmls into a resource

qml.qrc:

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

Then main.cpp must load it from the 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 check it works, then deploy as follows:

  • locate the releasse directory where your EXE lives
  • locate 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 location of windeployqt to PATH eg. C:\Qt\Qt5.5.1\5.5\msvc2013\bin

like image 99
jkj yuio Avatar answered Nov 15 '22 18:11

jkj yuio


As mentioned by BaCaRoZzo, a general solution that worked pretty well for me is to follow this guide.

To sum it up, copy in an empty directory:

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

First, during the test of your application, rename your qt folder so it is not found by $PATH, and double-click on MyApp.exe. This should run the program.

NB: It leads to a very big application, so you will need to delete some extra files and folders. The easiest way is for the dll: you run the program, and while being run, you delete all the dll in your new project. Only the ones that are not used by MyApp.exe will be deleted. Efficient!
For the Qt folders, proceed by trials and errors.

like image 33
PJ127 Avatar answered Sep 20 '22 22:09

PJ127


If you use MinGW, then try to copy all folders from folders qml and plugins to directory with your program. Also copy 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

Eventually 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 way works on WindowsXP/Win7 where Qt was not installed.

like image 7
indalive Avatar answered Nov 15 '22 17:11

indalive


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

like image 2
FourtyTwo Avatar answered Nov 15 '22 19:11

FourtyTwo