user6635665
user6635665

Reputation: 347

QT_VERSION Incorrect?

I'm working on a Qt Android application (Qt 5.11.1)and trying to make use of a library which checks against the version of Qt using QT_VERSION from QtGlobal.

I get errors compiling due to functions not being available and it seems to be because the reported Qt version is incorrect, (the library looks for #if QT_VERSION >= 0x050000 ...)

Adding the following trace statements;

qDebug() << "QT VERSION: " << QT_VERSION;
qDebug() << "QT STRING: " << QT_VERSION_STR;

Gives the output:

... (int main(int, char**)): QT VERSION:  330497
... (int main(int, char**)): QT STRING:  5.11.1

The string seems correct but the version number doesn't look right.

I'm working on a Windows 7 machine with Qt Creator 4.7 installed along with Qt 5.11.1 and 5.10.1 installed through the maintenance tool. The build settings are just the defaults for Android.

I'm not overly familiar with Qt and unsure of where to go from here so any help would be greatly appreciated.

Upvotes: 3

Views: 1824

Answers (2)

mohammads
mohammads

Reputation: 228

According to Qt documents:

QT_VERSION

This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that specifies Qt's version number. For example, if you compile your application against Qt 4.1.2, the QT_VERSION macro will expand to 0x040102.

Means it has to convert to a Hex number, then it will show you the Qt version number. Your returned number is 330497, so bringing this to Hexadecimal will be 0X50B01. Since B is 11 in Decimal, the version is 5.11.1.

QT_VERSION_STR

This macro expands to a string that specifies Qt's version number (for example, "4.1.2"). This is the version against which the application is compiled.

Upvotes: 6

Scheff&#39;s Cat
Scheff&#39;s Cat

Reputation: 20141

With some bit fiddling, the QT_VERSION can be separated into the major/minor/micro numbers.

testQT_VERSION.cc:

#include <QtCore>

int main()
{
  qDebug() << "QT_VERSION_STR:" << QT_VERSION_STR;
  qDebug() << "QT_VERSION:"
    << (((QT_VERSION) >> 16) & 0xff)
    << (((QT_VERSION) >> 8) & 0xff)
    << ((QT_VERSION) & 0xff);
  return 0;
}

testQT_VERSION.pro:

SOURCES = testQT_VERSION.cc

QT = core

Compiled and tested on cygwin64:

$ qmake-qt5 testQT_VERSION.pro

$ make

$ ./testQT_VERSION
QT_VERSION_STR: 5.9.4
QT_VERSION: 5 9 4

$

Also, worth to be noted:

const char* qVersion():

Returns the version number of Qt at run-time as a string (for example, "4.1.2"). This may be a different version than the version the application was compiled against.

Upvotes: 0

Related Questions