<QtVersionChecks> 代理页面
宏
QT_VERSION | |
QT_VERSION_CHECK(major, minor, patch) |
宏文档
QT_VERSION
该宏扩展为一个与QT_VERSION_CHECK() 结构形式相同的数值,它指定了使用该宏的代码所编译的 Qt 版本。例如,如果您使用 Qt 6.1.2 编译应用程序,QT_VERSION 宏将展开为0x060102
,与QT_VERSION_CHECK(6, 1, 2)
相同。请注意,这不必与应用程序在运行时使用的版本一致。
您可以使用 QT_VERSION 来选择最新的 Qt 功能,否则就会退回到旧的实现。建议使用QT_VERSION_CHECK() 作为比较值。
举例说明:
#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)
将一个版本的major 、minor 和patch 数字转换成一个整数,对所有三个数字进行编码。以十六进制表示时,该整数的形式为0xMMNNPP
,其中0xMM ==
major ,0xNN ==
minor ,以及0xPP ==
patch 。这可以与另一个经过类似处理的版本 ID 进行比较。
举例说明:
#include <QtGlobal> #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #include <QtWidgets> #else #include <QtGui> #endif
注意: 参数按正常方式作为整数读取,因此通常应以十进制书写(因此,如果以十六进制书写,则必须使用0x
前缀)。因此,QT_VERSION_CHECK(5, 15, 0)
等于0x050f00
,同样也可以写成QT_VERSION_CHECK(5, 0xf, 0)
。
另请参见 QT_VERSION 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.