Search code examples
qtqmakeqt5

qmake numeric variable comparation


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?


Solution

  • You can use:

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets