部署Qt Quick Controls 应用程序
Qt Quick Controls 应用程序的部署与其他类型的 Qt 应用程序非常相似。不过,有几个因素需要考虑。
部署具有多种样式的应用程序
假设您有一个将同时部署到 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 文件将包含针对 Universal 样式的配置选项:
[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 文件以查找导入语句。 因此,任何需供静态构建的应用程序使用的样式,都必须显式导入该样式。导入的位置由开发者自行决定,但建议遵循“部署具有多种样式的应用程序”一节中提到的方法,以便仅部署特定设备所需的最小文件集。
© 2026 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.