Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

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

    Tools
    2
    9
    1510
    Loading More Posts
    • 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
      PaperBirdMaster last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • P
          PaperBirdMaster last edited by

          [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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • P
              PaperBirdMaster last edited by

              [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 Reply Quote 0
              • P
                PaperBirdMaster last edited by

                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 Reply Quote 0
                • P
                  PaperBirdMaster last edited by

                  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 Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    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 Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      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 Reply Quote 0
                      • First post
                        Last post