- Qt 6.8
- Qt Core
- <QtVersionChecks> Proxy Page
- Qt 6.8.1 Reference Documentation

# <QtVersionChecks> Proxy Page

## Macros

| QT_VERSION
| QT_VERSION_CHECK(major, minor, patch)

## Macro Documentation

### QT_VERSION

This macro expands to a numeric value of the same form as QT_VERSION_CHECK() constructs, that specifies the version of Qt with which code using it is compiled. For example, if you compile your application with Qt 6.1.2, the QT_VERSION macro will expand to `0x060102`, the same as `QT_VERSION_CHECK(6, 1, 2)`. Note that this need not agree with the version the application will find itself using at runtime.

You can use QT_VERSION to select the latest Qt features where available while falling back to older implementations otherwise. Using QT_VERSION_CHECK() for the value to compare with is recommended.

Example:

     #if QT_VERSION >= QT_VERSION_CHECK(4, 1, 0)
         QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon);
     #else
         QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon);
         QIcon icon(pixmap);
     #endif

See also QT_VERSION_STR, QT_VERSION_CHECK(), and qVersion().

### QT_VERSION_CHECK(major, minor, patch)

Turns the major, minor and patch numbers of a version into an integer that encodes all three. When expressed in hexadecimal, this integer is of form `0xMMNNPP` wherein `0xMM ==` major, `0xNN ==` minor, and `0xPP ==` patch. This can be compared with another similarly processed version ID.

Example:

     #include <QtGlobal>

     #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
     #include <QtWidgets>
     #else
     #include <QtGui>
     #endif

Note: the parameters are read as integers in the normal way, so should normally be written in decimal (so a `0x` prefix must be used if writing them in hexadecimal). Thus `QT_VERSION_CHECK(5, 15, 0)` is equal to `0x050f00`, which could equally be written `QT_VERSION_CHECK(5, 0xf, 0)`.

See also QT_VERSION.