qt_policy

Modify the default behavior of Qt's CMake API.

命令的定义在 核心 组件对于 Qt6 包,可以像这样加载:

find_package(Qt6 REQUIRED COMPONENTS Core)
					

This command was introduced in Qt 6.5.

概要

qt_policy(
    [SET <policy_name> behavior]
    [GET <policy_name> <variable>]
)
					

无版本命令 被禁用,使用 qt6_policy() 代替。它支持如此命令的一组相同自变量。

描述

This command has two modes:

  • SET keyword is used, this command can be used to opt in to behavior changes in Qt's CMake API, or to explicitly opt out of them.
  • GET keyword is used, <variable> is set to the current behavior for the policy, i.e. OLD or NEW .

<policy_name> must be the name of one of the Qt CMake 策略 . Policy names have the form of QTP<NNNN> where <NNNN> is an integer specifying the index of the policy. Using an invalid policy name results in an error.

Code supporting older Qt versions can check the existence of a policy by checking the value of the QT_KNOWN_POLICY_<policy_name> variable before getting the value of <policy_name> or setting its behavior.

if(QT_KNOWN_POLICY_<policy_name>)
    qt_policy(SET <policy_name> NEW)
endif()
					

You can set behavior to one of the following options:

  • NEW to opt into the new behavior
  • OLD to explicitly opt-out of it

注意: The OLD behavior of a policy is deprecated, and may be removed in the future.

另请参阅 qt_standard_project_setup .