diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 7759b07d8fe..89478ebef5a 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -71,6 +71,7 @@ qt_internal_add_module(Core global/qtnamespacemacros.h global/qtrace_p.h global/qtranslation.h + global/qtversionchecks.h global/qtypeinfo.h global/qvolatile_p.h global/q20algorithm.h diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 9811a6003ae..f8db9e948ee 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1214,50 +1214,6 @@ static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined"); \sa qMin(), qMax() */ -/*! - \macro QT_VERSION_CHECK(major, minor, patch) - \relates - - Turns the \a major, \a minor and \a patch numbers of a version into an - integer that encodes all three. When expressed in hexadecimal, this integer - is of form \c 0xMMNNPP wherein \c{0xMM ==} \a major, \c{0xNN ==} \a minor, - and \c{0xPP ==} \a patch. This can be compared with another similarly - processed version ID. - - Example: - - \snippet code/src_corelib_global_qglobal.cpp qt-version-check - - \note the parameters are read as integers in the normal way, so should - normally be written in decimal (so a \c 0x prefix must be used if writing - them in hexadecimal). Thus \c{QT_VERSION_CHECK(5, 15, 0)} is equal to \c - 0x050f00, which could equally be written \c{QT_VERSION_CHECK(5, 0xf, 0)}. - - \sa QT_VERSION -*/ - -/*! - \macro QT_VERSION - \relates - - This macro expands to a numeric value of the same form as \l - 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 \c 0x060102, the same as - \c{QT_VERSION_CHECK(6, 1, 2)}. Note that this need not agree with the - version the application will find itself using at \e 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: - - \snippet code/src_corelib_global_qglobal.cpp 16 - - \sa QT_VERSION_STR, QT_VERSION_CHECK(), qVersion() -*/ - /*! \macro QT_VERSION_STR \relates diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index a161170c99d..a5584c22ee8 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -22,14 +22,7 @@ # include #endif -/* - QT_VERSION is (major << 16) | (minor << 8) | patch. -*/ -#define QT_VERSION QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH) -/* - can be used like #if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)) -*/ -#define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch)) +#include #ifdef QT_BOOTSTRAPPED #include diff --git a/src/corelib/global/qtversionchecks.cpp b/src/corelib/global/qtversionchecks.cpp new file mode 100644 index 00000000000..1e80eab63cf --- /dev/null +++ b/src/corelib/global/qtversionchecks.cpp @@ -0,0 +1,46 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! + \macro QT_VERSION_CHECK(major, minor, patch) + \relates + + Turns the \a major, \a minor and \a patch numbers of a version into an + integer that encodes all three. When expressed in hexadecimal, this integer + is of form \c 0xMMNNPP wherein \c{0xMM ==} \a major, \c{0xNN ==} \a minor, + and \c{0xPP ==} \a patch. This can be compared with another similarly + processed version ID. + + Example: + + \snippet code/src_corelib_global_qglobal.cpp qt-version-check + + \note the parameters are read as integers in the normal way, so should + normally be written in decimal (so a \c 0x prefix must be used if writing + them in hexadecimal). Thus \c{QT_VERSION_CHECK(5, 15, 0)} is equal to \c + 0x050f00, which could equally be written \c{QT_VERSION_CHECK(5, 0xf, 0)}. + + \sa QT_VERSION +*/ + +/*! + \macro QT_VERSION + \relates + + This macro expands to a numeric value of the same form as \l + 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 \c 0x060102, the same as + \c{QT_VERSION_CHECK(6, 1, 2)}. Note that this need not agree with the + version the application will find itself using at \e 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: + + \snippet code/src_corelib_global_qglobal.cpp 16 + + \sa QT_VERSION_STR, QT_VERSION_CHECK(), qVersion() +*/ diff --git a/src/corelib/global/qtversionchecks.h b/src/corelib/global/qtversionchecks.h new file mode 100644 index 00000000000..b02849e96da --- /dev/null +++ b/src/corelib/global/qtversionchecks.h @@ -0,0 +1,21 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QTVERSIONCHECKS_H +#define QTVERSIONCHECKS_H + +#if 0 +#pragma qt_class(QtVersionChecks) +#pragma qt_sync_stop_processing +#endif + +/* + QT_VERSION is (major << 16) | (minor << 8) | patch. +*/ +#define QT_VERSION QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH) +/* + can be used like #if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)) +*/ +#define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch)) + +#endif /* QTVERSIONCHECKS_H */