diff options
-rw-r--r-- | src/corelib/global/qglobal.cpp | 2 | ||||
-rw-r--r-- | src/corelib/global/qlibraryinfo.cpp | 13 | ||||
-rw-r--r-- | src/corelib/global/qlibraryinfo.h | 5 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp | 13 |
4 files changed, 32 insertions, 1 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 320fe50b4c..012202fe44 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1033,7 +1033,7 @@ Q_STATIC_ASSERT_X(QT_POINTER_SIZE == sizeof(void *), "QT_POINTER_SIZE defined in example, "4.1.2"). This may be a different version than the version the application was compiled against. - \sa QT_VERSION_STR + \sa QT_VERSION_STR, QLibraryInfo::version() */ const char *qVersion() Q_DECL_NOTHROW diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 458200180e..70e19d1f86 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -366,6 +366,19 @@ QLibraryInfo::isDebugBuild() #endif } +#ifndef QT_BOOTSTRAPPED +/*! + \since 5.8 + Returns the version of the Qt library. + + \sa qVersion() +*/ +QVersionNumber QLibraryInfo::version() Q_DECL_NOTHROW +{ + return QVersionNumber(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH); +} +#endif // QT_BOOTSTRAPPED + #endif // QT_BUILD_QMAKE /* diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h index 362d47dea3..a1c146923e 100644 --- a/src/corelib/global/qlibraryinfo.h +++ b/src/corelib/global/qlibraryinfo.h @@ -42,6 +42,7 @@ #include <QtCore/qstring.h> #include <QtCore/qdatetime.h> +#include <QtCore/qversionnumber.h> QT_BEGIN_NAMESPACE @@ -63,6 +64,10 @@ public: static bool isDebugBuild(); +#ifndef QT_BOOTSTRAPPED + static QVersionNumber version() Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; +#endif + enum LibraryLocation { PrefixPath = 0, diff --git a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp index 34d9256244..c37a15089a 100644 --- a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp +++ b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp @@ -29,6 +29,7 @@ #include <QtTest/QtTest> #include <QtCore/qversionnumber.h> +#include <QtCore/qlibraryinfo.h> class tst_QVersionNumber : public QObject { @@ -79,6 +80,7 @@ private slots: void serialize_data(); void serialize(); void moveSemantics(); + void qtVersion(); }; void tst_QVersionNumber::singleInstanceData() @@ -636,6 +638,17 @@ void tst_QVersionNumber::moveSemantics() #endif } +void tst_QVersionNumber::qtVersion() +{ + QVersionNumber v = QLibraryInfo::version(); + QVERIFY(!v.isNull()); + QCOMPARE(v.majorVersion(), QT_VERSION_MAJOR); + // we can't compare the minor and micro version: + // the library may change without the test being recompiled + + QCOMPARE(v.toString(), QString(qVersion())); +} + QTEST_APPLESS_MAIN(tst_QVersionNumber) #include "tst_qversionnumber.moc" |