Deploy Qt5 QML application

前端 未结 5 1598
广开言路
广开言路 2020-12-03 11:49

To test QML deployment I\'ve created a very simple QML application. Here is the code:

main.cpp

#include 

        
相关标签:
5条回答
  • 2020-12-03 12:15

    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.

    0 讨论(0)
  • 2020-12-03 12:18

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

    0 讨论(0)
  • 2020-12-03 12:21

    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.

    0 讨论(0)
  • 2020-12-03 12:25

    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.

    If you need use windows version just install application from installer

    0 讨论(0)
  • 2020-12-03 12:27

    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

    0 讨论(0)
提交回复
热议问题