Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qmake numeric variable comparation

Tags:

qt

qt5

qmake

I've downloaded Qt 5 and tried to build my project. Projects are now required to add widgets to QT variable, but that produces a warning with older version:

Project MESSAGE: Warning: unknown QT: widgets

The simple solution seem to add a simple check:

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

That did not worked (QT 4 is printed). 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 did not worked, either. Various other combinations like contains( "$$QT_MAJOR_VERSION", "5" ) do not work.

The assumption that $$QT_MAJOR_VERSION is 4 or 5 is checked with a line like:

message( $$QT_MAJOR_VERSION )

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

The conclusion to all this is that I don't understand something fundamental about qmake mechanism. So how does one compares a variable against a value in qmake .pro file?

like image 884
Nicu Tofan Avatar asked Feb 04 '13 07:02

Nicu Tofan


3 Answers

You can use:

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
like image 66
Zlatomir Avatar answered Nov 07 '22 20:11

Zlatomir


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

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

like image 32
UmNyobe Avatar answered Nov 07 '22 20:11

UmNyobe


It appears that

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

does not work, but

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

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

like image 25
CDA Avatar answered Nov 07 '22 20:11

CDA