qt_policy | Qt Core | Qt 6.10.3
Description: Modify the default behavior of Qt's CMake API.

- Qt 6.10
- Qt Core
- CMake Commands in Qt6 Core
- qt_policy
- Qt 6.10.3 Reference Documentation

# qt_policy

Modify the default behavior of Qt's CMake API.

The command is defined in the `Core` component of the `Qt6` package, which can be loaded like so:

     find_package(Qt6 REQUIRED COMPONENTS Core)

This command was introduced in Qt 6.5.

## Synopsis

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

If versionless commands are disabled, use `qt6_policy()` instead. It supports the same set of arguments as this command.

## Description

This command has two modes:

- When the `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.
- When the `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

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

See also qt_standard_project_setup.