Modify the default behavior of Qt's CMake API.
The command is defined in the
核心
组件对于
Qt6
package, which can be loaded like so:
find_package(Qt6 REQUIRED COMPONENTS Core)
This command was introduced in Qt 6.5.
qt_policy( [SET <policy_name> behavior] [GET <policy_name> <variable>] )
若
versionless commands
are disabled, use
qt6_policy()
instead. It supports the same set of arguments as this command.
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 policies
. 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 .