本文介绍了部署 Qt5 QML 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了测试 QML 部署,我创建了一个非常简单的 QML 应用程序.代码如下:

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
}

为了确保系统中没有安装开发库,我设置了一个安装了纯 Windows XP 的虚拟机.然后,我按照此处所述的说明操作并复制了all Qt5*.dll 进入程序目录,以及platforms/qwindows.dll 和icu*52.dll.Dependency Walker 确认没有留下损坏的依赖项,即一切都应该正确设置.

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.

我做错了什么?我如何部署 QML 应用以确保它可以在任何其他非开发机器上运行?

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

推荐答案

如果您使用 MinGW,则尝试将文件夹 qmlplugins 中的所有文件夹复制到目录中你的程序.同时复制库:icudt52.dllicuin52.dllicuuc52.dlllibgcc_s_dw2-1.dlllibstdc++-6.dlllibwinpthread-1.dllQt5Core.dllQt5Gui.dllQt5Network.dllQt5Qml.dllQt5Quick.dllQt5Svg.dllQt5Widgets.dll代码>来自bin

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

最终目录将如下所示:

  • 引擎
  • 图像格式
  • 平台
  • Qt
  • QtGraphicalEffects
  • Qt定位
  • QtQml
  • QtQuick
  • QtQuick.2
  • Qt传感器
  • 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

这种方式适用于未安装 Qt 的 WindowsXP/Win7.

This way works on WindowsXP/Win7 where Qt was not installed.

这篇关于部署 Qt5 QML 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 02:25
查看更多