Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Changing variables on *.pro file don't affect the code
QtWS25 Last Chance

Changing variables on *.pro file don't affect the code

Scheduled Pinned Locked Moved Qt Creator and other tools
9 Posts 2 Posters 2.0k Views
  • 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.
  • P Offline
    P Offline
    PaperBirdMaster
    wrote on last edited by
    #1

    I have a project which stores part of its configuration on the *.pro file, the configuration is switched using a variable on the top of the file in order to make it easier for the team to change configurations, let's see a short example:

    @# ------------------ #

    Project connection

    ------------------

    CONNECTIONS = ARRAKIS

    ------------------ #@

    At the end of the *.pro file, all the "magic" is done:

    @contains(CONNECTIONS, ARRAKIS) {
    HOST_ADDRESS = "http://arrakis.dune.net"
    API_ADDRESS = "/projects/foo/bar/baz/"
    LOGIN_ADDRESS = "/projects/oauth/arrakis_login.php"
    }

    contains(CONNECTIONS, NAMEK) {
    HOST_ADDRESS = "http://namek.com"
    API_ADDRESS = "/nyi/publicapi/"
    LOGIN_ADDRESS = "/projects/oauth/namek_login.php"
    }

    DEFINES += HOST_ADDRESS=\"$$HOST_ADDRESS\"
    API_ADDRESS=\"$$API_ADDRESS\"
    LOGIN_ADDRESS=\"$$LOGIN_ADDRESS\" @

    Finally in the C++ code, the defines configured on the project file are used like this:

    @const QString HOST = QStringLiteral(HOST_ADDRESS);
    const QString API = QStringLiteral(API_ADDRESS);
    const QString LOGIN = QStringLiteral(LOGIN_ADDRESS);@

    So, what's the problem?

    If someone changes the CONNECTIONS variable and builds the project, the binaries are generated with the values of the previous configuration unless a complete rebuild is performed, this is pretty cumbersome and makes all the configuration stuff nearly useless (due to the fact that rebuild this project takes several minutes).

    What I have tryed so far?

    Unexpected result (defines not updated).

    Change configuration.

    Build.

    Unexpected result (defines not updated).

    Change configuration.

    Run qMake.

    Build.

    Expected result (defines updated).

    Change configuration.

    REBuild.

    Expected result (defines updated).

    Change configuration.

    Make a dummy change in the cpp file that uses this defines (for example insert a new line)

    Build.

    Is there any way to achieve the expected results without rebuild the project or making dummy changes on the code?

    Any help would be appreciated,

    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Not the answer you would like but AFAIK, currently there's not.

      [edit: corrected misleading typo]

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PaperBirdMaster
        wrote on last edited by
        #3

        [quote author="SGaist" date="1413887761"]Hi and welcome to devnet,

        Not the answer you would like bug AFAIK, currently there's not. [/quote]
        Sorry for my poor english skills ó_ò if I'm understanding well, you're saying that this is a bug?

        If it is a bug, could you lead me to report it (unless it is already reported).

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Sorry it was a typo not bug

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            PaperBirdMaster
            wrote on last edited by
            #5

            [quote author="SGaist" date="1413888427"]Sorry it was a typo not bug[/quote]

            Danm! what a funny typo :D

            You're right: unfortunately it's not the answer I'll like; now I only can pray for the Qt team to "fix" this.

            Thanks a lot.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PaperBirdMaster
              wrote on last edited by
              #6

              I've solved the problem using the touch command in the pro file:

              touch(file_i_want_to_be_compiled_1.cpp, my_project.pro)
              touch(file_i_want_to_be_compiled_2.cpp, my_project.pro)
              touch(file_i_want_to_be_compiled_3.cpp, my_project.pro)
              and so on...

              Isn't pretty, isn't neat... but it works.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                PaperBirdMaster
                wrote on last edited by
                #7

                I've solved the problem using the touch command in the pro file:

                touch(file_i_want_to_be_compiled_1.cpp, my_project.pro)
                touch(file_i_want_to_be_compiled_2.cpp, my_project.pro)
                touch(file_i_want_to_be_compiled_3.cpp, my_project.pro)
                and so on...

                Isn't pretty, isn't neat... but it works.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You could also use the find command to automate that a bit

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    You could also use the find command to automate that a bit

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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