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?
You can use:
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With