How can you test if a variable is empty or not defined in a qmake
.pro
file? I want to
be able to set up a default value if the variable is not defined.
I tried
eval("VARIABLE" = ""){
VARIABLE = test
}
eval("VARIABLE" = ""){
message(variable is empty)
}
but I still get the message "variable is empty".
there is already the function isEmpty I didn't spot:
isEmpty(VARIABLE){
VARIABLE = test
}
isEmpty(VARIABLE ){
message(variable is empty)
}
I don't understand why eval didnt work thought...
Like your own answer says, isEmpty(VARIABLE)
does what you want:
isEmpty(VARIABLE) {
...
}
The qmake language has no equivalent of an equals operator (==
), but you can compare things like this:
equals(VARIABLE, foo) {
...
}
You can also check if a variable contains a substring, using a regular expression:
contains(VARIABLE, .*foo.*) {
...
}
The reason why eval()
didn't work, is that it executes the statement within it and returns true if the statement succeeded.
So by doing this:
eval(VARIABLE = "") {
...
}
...you are actually assigning ""
to VARIABLE
, making the variable empty and entering the block.
More about test functions: http://qt-project.org/doc/qt-5/qmake-test-function-reference.html
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