qt_deploy_qml_imports
部署所需执行的 QML 模块运行时组件。
该命令在 Qt6 包的 Qml 组件中定义,可以如下加载
find_package(Qt6 REQUIRED COMPONENTS Qml)
与其他大多数由 Qt 提供的 CMake 命令不同,qt6_deploy_qml_imports 只能从部署脚本中调用。它不能直接由项目调用。
警告:如果您正在使用低于 3.19 的 CMake 版本,请确保将 MANUAL_FINALIZATION 选项传递给 qt6_add_executable(),然后在调用此函数之前调用 qt6_finalize_target()。
说明
qt_deploy_qml_imports(
TARGET target
[QML_DIR qml_dir]
[PLUGINS_FOUND var_name]
[NO_QT_IMPORTS]
)描述
注意:此命令通常不需要直接调用。它由其他更高级别的命令内部使用,但对于想实现更定制化部署逻辑的项目可能有用。
当安装使用 QML 的应用程序时,可能很难确定哪些 QML 模块以及这些模块的哪些部分也需要安装。因为 QML 插件并没有直接链接到应用程序的可执行文件,qt_deploy_runtime_dependencies() 将无法找到这些 QML 模块。命令 qt6_deploy_qml_imports 提供了必要的逻辑,与 qt_deploy_runtime_dependencies() 相辅相成,并部署了应用程序引入的所有 QML 模块的运行时部分。
选项 TARGET 是强制性的,应指定一个 target,它是一个可执行文件(在 macOS 上,它应该是 app bundle)并也是一个 QML 模块。所有通过 qt_add_qml_module() 或 qt_target_qml_sources() 添加到 target 的 QML 源将递归地扫描 QML 导入。必须没有为 qt_add_qml_module() 提供 NO_IMPORT_SCAN 选项。将从导入的 QML 模块部署 qmldir 文件和插件。可以提供 NO_QT_IMPORTS 选项以跳过部署任何由 Qt 提供的 QML 模块。
默认情况下,导入的 QML 模块的运行时部分将部署到 macOS 应用程序包的 Resources/qml 目录,以及其他平台基础安装位置的 qml 目录。对于非 macOS 的情况,可以使用 QML_DIR 选项来覆盖此默认选择。
如果提供了 PLUGINS_FOUND 选项,则命令将在名为该选项变量的变量中存储它部署的所有 QML 插件列表。这通常在后继对 qt_deploy_runtime_dependencies() 的调用中作为 ADDITIONAL_MODULES 参数传递。
示例
cmake_minimum_required(VERSION 3.16...3.22)
project(MyThings)
find_package(Qt6 6.3 REQUIRED COMPONENTS Core Qml)
qt_standard_project_setup()
qt_add_executable(MyApp main.cpp)
qt_add_qml_module(MyApp
URI Application
VERSION 1.0
QML_FILES main.qml MyThing.qml
)
# The following script must only be executed at install time
set(deploy_script "${CMAKE_CURRENT_BINARY_DIR}/deploy_MyApp.cmake")
file(GENERATE OUTPUT ${deploy_script} CONTENT "
include(\"${QT_DEPLOY_SUPPORT}\")
qt_deploy_qml_imports(
# Deploy QML modules used by MyApp
TARGET MyApp
# The found QML plugins are stored in the plugins_found variable
PLUGINS_FOUND plugins_found
# The QML modules will be deployed into a custom directory
QML_DIR \"myqmldir\"
# Qt QML modules will be skipped, only project-created QML modules will be deployed
NO_QT_IMPORTS
)
# Deploy application runtime dependencies and runtime dependencies
# of the found QML module plugins.
qt_deploy_runtime_dependencies(
EXECUTABLE $<TARGET_FILE:MyApp>
ADDITIONAL_MODULES \${plugins_found}
)
")
install(TARGETS MyApp)
install(SCRIPT ${deploy_script})另请参阅:qt_generate_deploy_qml_app_script()、qt_deploy_runtime_dependencies() 和 QT_DEPLOY_QML_DIR。
© © 2024 The Qt Company Ltd. 本文档中包含的贡献属于各自所有者的版权。提供的文档根据自由软件基金会发布的 GNU自由文档许可协议版本1.3 许可。Qt及其相关标志是芬兰和/或其他国家的The Qt Company Ltd. 的商标。所有其他商标都是其各自所有者的财产。