14

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?

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
folibis
  • 12,048
  • 6
  • 54
  • 97
  • 2
    Build your app with CONFIG += console in project file to get errors in console. Also note that QtQuick2 application may not work in VirtualBox as it has issues with OpenGL – nib Jul 31 '14 at 07:10
  • use windeployqt --qmldir f:\myApp\sources f:\build-myApp\myApp.exe command. – Harshad Karemore Aug 09 '21 at 13:38

8 Answers8

7

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.

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
indalive
  • 300
  • 1
  • 5
  • 2
    The general procedure is discussed [here](http://qt-project.org/wiki/Deploy_an_Application_on_Windows). Rough but effective. – BaCaRoZzo Dec 16 '14 at 14:14
6

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

jkj yuio
  • 2,543
  • 5
  • 32
  • 49
  • "locate the directory where your QML lives", then I pass the QML directory path relative to what? do I need to copy the QML files to this new directory "created somewhere"? – Bersan Nov 21 '22 at 14:56
2

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

FourtyTwo
  • 1,616
  • 2
  • 15
  • 43
  • Yeah, like it works... unfortunately this is currently not the case. – dtech Feb 11 '16 at 14:34
  • @ddriver What is currently not the case? – FourtyTwo Feb 12 '16 at 07:18
  • The deployment tool doesn't work, neither for DLLs, nor for QML files. It doesn't collect the needed files, and it even collects files which aren't needed at all for the project. It is as broken as it gets. – dtech Feb 12 '16 at 11:53
  • 2
    I've been using the deployment tool since Qt 5.3, and it works like a charm - and my project is quite large, some of the dll dependencies even come from qml files. You will need the --qmldir parameter as soon as you have included qml resources (like jkj yuio correctly states in his answer, and like the documentation I linked tells you) for this to work, before I discovered this switch I had the same issues as you are mentioning ;-) – FourtyTwo Feb 18 '16 at 14:10
  • I am using the tool as intended it just doesn't work. Note I am using a 64bit build, maybe it works better for 32bit... – dtech Feb 18 '16 at 14:26
  • @ddriver Did you file a bug report? – Mitch Apr 07 '16 at 12:55
  • @Mitch - I have totally lost motivation to do such things. Judging by the amount of work done on critical bugs I've reported so far, or more like the lack of any, it seems it will be a wasted effort :( Also, I don't seem to be able to log-in since the latest account "unification"... – dtech Apr 07 '16 at 15:12
  • what is supposed to go on the argument of `--qmldir`? is it the path to the QML of my application or the windows QML libraries? – Bersan Nov 21 '22 at 14:49
1

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.

PJ127
  • 986
  • 13
  • 23
  • you'd think in an integrated, independent development environment, you would just press a button and get the executable as in every other programing language or framework ever... no, in QT you need to follow a guide that tells you to follow another guide, telling you to essentially copy every single file you need manually. Why are they even releasing new versions when the old ones don't even do the most basic thing you could ask for? – Bersan Nov 21 '22 at 14:43
0

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

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

You can install from github releases (Windows)

or

from snapstore (Linux)

sudo snap install cqtdeployer

You can use as follows:

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

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

And Run application with sh script (Linux) or exe (Windows)

If you'll use the version from snap then make sure that you have all the permissions. cqtdeployer

If you need use windows version just install application from installer

Andrey Yankovich
  • 868
  • 9
  • 13
0

use windeployqt --qmldir f:\myApp\sources f:\build-myApp\myApp.exe command. the first argument after qmldir is your qml folder location and the second argument is where your exe is placed. You would get deployable exe on any env.

0

For me this answer worked for a QtQuick 2 application (QML app), but I'm adding more details:

  • Build inside Qt as Release

  • Find the folder in the file explorer with the executable, usually on a sibling folder to your project folder

  • Copy executable to an empty folder

  • Start Qt CMD tool (mine is ), go to the folder with the executable and run:

windeployqt --release --qmldir C:\Qt\5.15.1\msvc2015_64\qml executable.exe

(change 5.15.1\msvc2015_64 for yours)

Bersan
  • 1,032
  • 1
  • 17
  • 28
0

My answer was:

(1) On Qt Framework set the Release mode for my Application.

(2) After: Project -> Build directory and set a empty directory in the "C:/" folder (I'm development Windows 10). Example: My Folder: "Release" with subfolder "My_app", so the Build directory is "C:/Release/My_app"

(3) Click on "Start debuggin of the startup project"

(4) Create another folder on "C:/" directory (in my case callet "Executable" with subfolder "My_app").

(5) Copy "My_app.exe" of the folder "Release/My_app/release" to "C:/Executable/My_app").

(6) Open Qt mingw.

(7) On the terminal of the Qt MinGw go to folder "Release/My_app/release" through command "cd C:/Executable/My_app"

(8) Run the command "windeploy.exe My_app.exe --qmldir 'full_path_where_are_the_qml_files'" (e.g.: "C:/My_prj/qmlsource", where qmlsource is folder with my qml_files).

This generate all files to run My_app.exe. Just the copy all folder (My_prj folder).