<QtVersionChecks> Proxy Page

QT_VERSION
QT_VERSION_CHECK ( major , minor , patch )

宏文档编制

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.

范例:

#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
					

另请参阅 QT_VERSION_STR , QT_VERSION_CHECK (),和 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 ,和 0xPP == patch . This can be compared with another similarly processed version ID.

范例:

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

注意: 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) 等于 0x050f00 , which could equally be written QT_VERSION_CHECK(5, 0xf, 0) .

另请参阅 QT_VERSION .