Encourage use of QT_VERSION_CHECK()
Document that QT_VERSION should normally be compared against it, rather than raw hex, and mildly update the example versions used in docs. (Left the snippets testing old version, since the code in which the #if-ery is used might actually make sense for those versions.) Improve related documentation in the process. Change-Id: Id3e97f41bfb0f81a117cf7b3a3ccd5f244e2a99a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
7943480f0f
commit
44028a227e
@ -203,7 +203,7 @@ int boundedValue = qBound(minValue, myValue, maxValue);
|
|||||||
|
|
||||||
|
|
||||||
//! [16]
|
//! [16]
|
||||||
#if QT_VERSION >= 0x040100
|
#if QT_VERSION >= QT_VERSION_CHECK(4, 1, 0)
|
||||||
QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon);
|
QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon);
|
||||||
#else
|
#else
|
||||||
QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon);
|
QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon);
|
||||||
@ -718,7 +718,7 @@ bool readConfiguration(const QFile &file)
|
|||||||
//! [qt-version-check]
|
//! [qt-version-check]
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#else
|
#else
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
@ -1302,17 +1302,24 @@ static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\macro QT_VERSION_CHECK
|
\macro QT_VERSION_CHECK(major, minor, patch)
|
||||||
\relates <QtGlobal>
|
\relates <QtGlobal>
|
||||||
|
|
||||||
Turns the major, minor and patch numbers of a version into an
|
Turns the \a major, \a minor and \a patch numbers of a version into an
|
||||||
integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can
|
integer that encodes all three. When expressed in hexadecimal, this integer
|
||||||
be compared with another similarly processed version id.
|
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:
|
Example:
|
||||||
|
|
||||||
\snippet code/src_corelib_global_qglobal.cpp qt-version-check
|
\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). Thuse \c{QT_VERSION_CHECK(5, 15, 0)} is equal to \c
|
||||||
|
0x050e00, which could equally be written \c{QT_VERSION_CHECK(5, 0xe, 0)}.
|
||||||
|
|
||||||
\sa QT_VERSION
|
\sa QT_VERSION
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -1320,19 +1327,22 @@ static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
|
|||||||
\macro QT_VERSION
|
\macro QT_VERSION
|
||||||
\relates <QtGlobal>
|
\relates <QtGlobal>
|
||||||
|
|
||||||
This macro expands a numeric value of the form 0xMMNNPP (MM =
|
This macro expands to a numeric value of the same form as \l
|
||||||
major, NN = minor, PP = patch) that specifies Qt's version
|
QT_VERSION_CHECK() constructs, that specifies the version of Qt with which
|
||||||
number. For example, if you compile your application against Qt
|
code using it is compiled. For example, if you compile your application with
|
||||||
4.1.2, the QT_VERSION macro will expand to 0x040102.
|
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 use the latest Qt features where
|
You can use QT_VERSION to select the latest Qt features where available
|
||||||
available.
|
while falling back to older implementations otherwise. Using
|
||||||
|
QT_VERSION_CHECK() for the value to compare with is recommended.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
\snippet code/src_corelib_global_qglobal.cpp 16
|
\snippet code/src_corelib_global_qglobal.cpp 16
|
||||||
|
|
||||||
\sa QT_VERSION_STR, qVersion()
|
\sa QT_VERSION_STR, QT_VERSION_CHECK(), qVersion()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -53,11 +53,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
QT_VERSION is (major << 16) + (minor << 8) + patch.
|
QT_VERSION is (major << 16) | (minor << 8) | patch.
|
||||||
*/
|
*/
|
||||||
#define QT_VERSION QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_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(4, 4, 0))
|
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))
|
#define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user