Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qmake variable seems to be empty after assigning a variable to it in a !defined condition
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 823 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devjb
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      devjb
      wrote on last edited by
      #8

      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.

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        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?

        (Z(:^

        1 Reply Last reply
        0
        • D Offline
          D Offline
          devjb
          wrote on last edited by
          #3

          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: ...
          
          J.HilkJ 1 Reply Last reply
          0
          • D devjb

            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: ...
            
            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #4

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


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #5

              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?

              (Z(:^

              1 Reply Last reply
              0
              • D Offline
                D Offline
                devjb
                wrote on last edited by
                #6

                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.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  devjb
                  wrote on last edited by
                  #7

                  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.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    devjb
                    wrote on last edited by
                    #8

                    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.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved