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. global vars in .pro file

global vars in .pro file

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.2k 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.
  • X Offline
    X Offline
    xalisonx
    wrote on last edited by
    #1

    Hi all, I need to deploy my qt application in various "version". The difference between this versions are only the repository where the application read the initial configuration.

    My idea is to define a variable in the .pro, and then use this in my cpp code also.
    (I have to change the "TARGET" in the .pro).
    Is it possible?
    What is the best solution?

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

      Hi,

      Do you mean something like:
      qmake MYCONFIG=foo

      contains(MYCONFIG, foo) {
      TARGET = foo_bar
      }
      

      ?

      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
      • X Offline
        X Offline
        xalisonx
        wrote on last edited by
        #3

        Hi SGaist,
        thanks for your support!

        I mean something like, in the .pro file:

        TARGET = MYAPPNAME
        DEFINES+= MYTARGET="$${TARGET}"
        

        I would use the MYTARGET in the cpp code, like this:

        QString baseRepository = "/basepath/"+ MYTARGET;
        

        Or something similar?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          swegmann
          wrote on last edited by
          #4

          Hi,

          What you could do is this in the .pro file:

          TARGET = foo
          DEFINES += MYTARGET="$(TARGET)"

          However then you need to make sure to use the MYTARGET define in your source code with some sort of stringify mechanism to turn it into a string. You find lots of hits if you search for "C++" and "Stringify", just like http://stackoverflow.com/questions/20384709/how-to-stringify-a-string-which-contains-a-comma

          Is this what you are looking for?

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

            The define itself will also need to escaped in order to have " correctly in the shell.

            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