qt_deploy_qt_conf

在部署时编写 qt.conf 文件。

该命令定义在Qt6 软件包的Core 组件中,可以像这样加载:

find_package(Qt6 REQUIRED COMPONENTS Core)

与 Qt 提供的大多数其他 CMake 命令不同,qt_deploy_qt_conf() 只能从部署脚本中调用。项目不能直接调用它。

此命令在 Qt 6.3 中引入。

注意: 通常不需要直接调用此命令。它在内部被其他更高级别的命令使用,但希望实现更多自定义部署逻辑的项目可能会发现它很有用。

简介

qt_deploy_qt_conf(file_path
    [PREFIX prefix]
    [DOC_DIR doc_dir]
    [HEADERS_DIR headers_dir]
    [LIB_DIR lib_dir]
    [LIBEXEC_DIR libexec_dir]
    [BIN_DIR bin_dir]
    [PLUGINS_DIR plugins_dir]
    [QML_DIR qml_dir]
    [ARCHDATA_DIR archdata_dir]
    [DATA_DIR data_dir]
    [TRANSLATIONS_DIR translations_dir]
    [EXAMPLES_DIR examples_dir]
    [TESTS_DIR test_dir]
    [SETTINGS_DIR settings_dir]
)

说明

在部署过程中需要生成qt.conf文件时使用此命令。qt.conf 支持的任何路径的默认值都可以用相应的..._DIR 选项覆盖。只有当路径与默认值不同时,该命令才会将路径写入生成的qt.conf 文件。默认值请参阅 "覆盖路径"。

file_path 参数需要一个绝对路径,指向qt.conf 文件应被写入的位置。QT_DEPLOY_PREFIXQT_DEPLOY_BIN_DIR变量可用于动态指定相对于部署二进制目录的路径,如下例所示。这有助于避免硬编码绝对路径。

示例

# The following script must only be executed at install time
qt_generate_deploy_script(
    OUTPUT_SCRIPT deploy_script
    CONTENT "
qt_deploy_qt_conf(\"\${QT_DEPLOY_PREFIX}/\${QT_DEPLOY_BIN_DIR}/qt.conf\"
    DATA_DIR \"./custom_data_dir\"
    TRANSLATIONS_DIR \"./custom_translations_dir\"
)
")

install(SCRIPT ${deploy_script})

另请参阅 qt_generate_deploy_app_script()qt_deploy_runtime_dependencies()

© 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.