Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qmake variable seems to be empty after assigning a variable to it in a !defined condition



  • Hi,

    I used to have the following block in my pro file

    QT_REQUIREDVERSION_MAJOR=5
    QT_REQUIREDVERSION_MINOR=12
    QT_REQUIREDVERSION_PATCH=7
    
    #version check qt
    !equals(QT_VERSION, "$${QT_REQUIREDVERSION_MAJOR}.$${QT_REQUIREDVERSION_MINOR}.$${QT_REQUIREDVERSION_PATCH}") {
    message("Cannot build with Qt version $${QT_VERSION}.")
    error("Use specific Qt version: $${QT_REQUIREDVERSION_MAJOR}.$${QT_REQUIREDVERSION_MINOR}.$${QT_REQUIREDVERSION_PATCH}.")
    }
    

    To gain flexibility to pass variables during the qmake call, I changed this to be:

    message(Defining required qt version variables)
    !defined(QT_REQUIREDVERSION_MAJOR){
    	QT_REQUIREDVERSION_MAJOR=5
    	message("Required Qt major version QT_REQUIREDVERSION_MAJOR has not been given, defaulting to $${QT_REQUIREDVERSION_MAJOR}")
    }
    !defined(QT_REQUIREDVERSION_MINOR){
    	QT_REQUIREDVERSION_MINOR=12
    	message("Required Qt minor version QT_REQUIREDVERSION_MINOR has not been given, defaulting to $${QT_REQUIREDVERSION_MINOR}")
    }
    !defined(QT_REQUIREDVERSION_PATCH){
    	QT_REQUIREDVERSION_PATCH=7
    	message("Required Qt patch version QT_REQUIREDVERSION_PATCH has not been given, defaulting to $${QT_REQUIREDVERSION_PATCH}")
    }
    
    #version check qt
    !equals(QT_VERSION, "$${QT_REQUIREDVERSION_MAJOR}.$${QT_REQUIREDVERSION_MINOR}.$${QT_REQUIREDVERSION_PATCH}") {
    	message("Cannot build with Qt version $${QT_VERSION}.")
    	error("Use specific Qt version: $${QT_REQUIREDVERSION_MAJOR}.$${QT_REQUIREDVERSION_MINOR}.$${QT_REQUIREDVERSION_PATCH}.")
    }
    

    With the result, that the variables are empty in the !equals() condition, but are correctly printed during the !defined() condition.
    How can I fix this? What am I doing wrong here?



  • Now I am absolutely confused. It is working. Maybe some Qt creator fuckup, I tested it on a different qt version in docker, where it worked, came back to qt creator, where it still did not, restarted qt creator and it worked....

    Sometimes qmake drives me crazy.


  • Moderators

    Here is output I get with your code:

    Project MESSAGE: Required Qt major version QT_REQUIREDVERSION_MAJOR has not been given, defaulting to 5
    Project MESSAGE: Required Qt minor version QT_REQUIREDVERSION_MINOR has not been given, defaulting to 12
    Project MESSAGE: Required Qt patch version QT_REQUIREDVERSION_PATCH has not been given, defaulting to 7
    Project MESSAGE: Cannot build with Qt version 5.15.1.
    Project ERROR: Use specific Qt version: 5.12.7.
    

    When I change Qt version to match, it also works as expected.

    What am I doing wrong here?

    Nothing, apparently. Your code, as posted, is correct.

    Maybe the code you have in .pro is slightly different (typos?) or gets executed in different order?



  • Weird.

    My Output with the exact same code:

    Project MESSAGE: Defining required qt version variables
    Project MESSAGE: Required Qt major version QT_REQUIREDVERSION_MAJOR has not been given, defaulting to 5
    Project MESSAGE: Required Qt minor version QT_REQUIREDVERSION_MINOR has not been given, defaulting to 12
    Project MESSAGE: Required Qt patch version QT_REQUIREDVERSION_PATCH has not been given, defaulting to 7
    Project MESSAGE: Cannot build with Qt version 5.12.7.
    Project ERROR: Use specific Qt version: ...
    

  • Moderators

    @devjb do you have a qmake.conf file inside your project folder (or the parent folders!) that may interfere?


  • Moderators

    Try running with different Qt version... maybe there is some bug in qmake in the release you are using?

    Check your code, maybe you are replacing the values somewhere else?



  • I try to reproduce the behaviour with a minimal example. I think the issue has to do with including that snippet in multiple pro files of my sub project. I hoped that I can achieve proper variable propagation top down in the nested projects, which apparently does not work correctly :-(

    When I have one single qmake file where I use the snippet, it seems to work.



  • In an empty project, I put a minimal example together:

    include(commonvariables.pri)
    
    #version check qt
    !equals(QT_VERSION, "$${QT_REQUIREDVERSION_MAJOR}.$${QT_REQUIREDVERSION_MINOR}.$${QT_REQUIREDVERSION_PATCH}") {
    	message("Cannot build with Qt version $${QT_VERSION}.")
    	error("Use specific Qt version: $${QT_REQUIREDVERSION_MAJOR}.$${QT_REQUIREDVERSION_MINOR}.$${QT_REQUIREDVERSION_PATCH}.")
    }
    message("Building allowed with Qt version $${QT_VERSION}")
    

    where commonvariables.pri is

    # variables for a whole build
    
    # define the required qt version to build the project
    message(Defining required qt version variables)
    !defined(QT_REQUIREDVERSION_MAJOR){
    	QT_REQUIREDVERSION_MAJOR=5
    	message("Required Qt major version QT_REQUIREDVERSION_MAJOR has not been given, defaulting to $${QT_REQUIREDVERSION_MAJOR}")
    }
    !defined(QT_REQUIREDVERSION_MINOR){
    	QT_REQUIREDVERSION_MINOR=12
    	message("Required Qt minor version QT_REQUIREDVERSION_MINOR has not been given, defaulting to $${QT_REQUIREDVERSION_MINOR}")
    }
    !defined(QT_REQUIREDVERSION_PATCH){
    	QT_REQUIREDVERSION_PATCH=7
    	message("Required Qt patch version QT_REQUIREDVERSION_PATCH has not been given, defaulting to $${QT_REQUIREDVERSION_PATCH}")
    }
    

    when i put the contents of commonvariable.pri in place, it works. I wonder why such an include of variables works in other places, where I alter for example LIBS or QT variables in .pri files but not here.



  • Now I am absolutely confused. It is working. Maybe some Qt creator fuckup, I tested it on a different qt version in docker, where it worked, came back to qt creator, where it still did not, restarted qt creator and it worked....

    Sometimes qmake drives me crazy.


Log in to reply