Qmake numeric variable comparison

I downloaded Qt 5 and tried to create my project. Now, to add a widget to the QT variable, projects are required, but this causes a warning with the old version:

MESSAGE About the project: warning: unknown QT: widgets

A simple solution seems to add a simple check:

equals( $$QT_MAJOR_VERSION, 5 ) { message(" ================ QT 5 ================ ") QT += widgets } else { message(" ================ QT 4 ================ ") } 

This did not work (QT 4 is printing). It is true that equals is not part of the qmake function reference , but contains is. So, tried with:

 contains( $$QT_MAJOR_VERSION, 5 ) { message(" ================ QT 5 ================ ") QT += widgets } else { message(" ================ QT 4 ================ ") } 

but that didn't work either. Various other combinations, such as contains ("$$ QT_MAJOR_VERSION", "5"), do not work.

It is assumed that the value of $$ QT_MAJOR_VERSION is 4 or 5 using a string like:

 message( $$QT_MAJOR_VERSION ) 

Setting up a local variable and testing its value in this way does not work.

The conclusion of all this is that I do not understand anything fundamental in the qmake mechanism. So how to compare a variable with a value in the qmake.pro file?

+7
source share
3 answers

You can use:

 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 
+10
source

Besides what Zlatomir said, greaterThan is a strict comparison (not "more and equal"). You can also use isEqual(QT_MAJOR_VERSION, 5) to check for numerical equality.

Note that you must not specify $$ for QT_MAJOR_VERSION , QT_MINOR_VERSION and QT_PATCH_VERSION .

+5
source

It seems that

 equals (QT_MAJOR_VERSION, 4) { //some conditional stuff } 

doesn't work but

 equals (QT_MAJOR_VERSION, 4) { //some conditional stuff } 

it works ... it is sensitive to the position of the opening bracket! Wierd

+3
source

All Articles