部署Qt Quick Controls 应用程序

Qt Quick Controls 应用程序的部署与其他类型 Qt XML 应用程序的部署非常相似。不过,有几个因素需要考虑。

部署具有多种样式的应用程序

假设您有一个应用程序将同时部署到 Android 和 Windows 设备上。为确保只将应用程序运行所需的最少文件集部署到每台设备,您可以使用文件选择器。例如,您的目录结构可以如下所示:

resources.qrc
main.qml
+windows/MyPage.qml
+windows/qtquickcontrols2.conf
+android/MyPage.qml
+android/qtquickcontrols2.conf

例如,在上述项目中,main.qml 将导入QtQuick.Controls ,但不应导入QtQuick.Controls.Material 。任何特定风格的代码都会被移到单独的文件中;就像我们对MyPage.qml 所做的那样。

+windows/qtquickcontrols2.conf 文件包含通用样式的特定配置选项:

[Controls]
Style=Universal

[Universal]
Theme=Dark
Accent=Red

+android/qtquickcontrols2.conf 文件将包含特定于 Material 风格的配置选项:

[Controls]
Style=Material

[Material]
Theme=Light
Accent=Brown

静态构建

对于动态构建的应用程序,没有必要导入该应用程序应使用的特定样式。对于静态构建的应用程序,Qt 的构建系统必须参与其中,以确保 QML 插件按预期运行。具体来说,qmake 使用qmlimportscanner 扫描应用程序中的 QML 文件,查找导入语句。因此,静态构建的应用程序应使用的任何样式都必须明确导入该样式。导入的位置由开发者决定,但建议遵循 "部署具有多种样式的应用程序"一节中提到的方法,以便只部署特定设备所需的最小文件集。

另请参阅 Qt Quick Controls部署 Qt 应用程序使用样式

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.