本页内容

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_PREFIX和QT_DEPLOY_BIN_DIR变量可用于动态指定相对于部署二进制目录的路径,如下例所示。这有助于避免硬编码绝对路径。

示例

注意: 下面的示例 旨在让${QT_DEPLOY_PREFIX} 和${QT_DEPLOY_BIN_DIR} 在运行生成的脚本时被展开。这仅在QTP0008设置为NEW 时有效。当行为设置为OLD 时,这两个引用会在传递参数的同时被展开,生成的脚本最终将包含qt_deploy_qt_conf("//qt.conf") 。

# The following script must only be executed at install time
qt_policy(SET QTP0008 NEW)

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() 以及QTP0008。

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