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 set GCC string variable

qmake set GCC string variable

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.4k Views 1 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
    deleted605
    wrote on last edited by
    #1

    Hi guys,

    I'm trying to assign a string value to a variable at compile time. Trying and googling about 2 days but no lack.

    Here's how I'm trying to do that.
    Below are in .pro file.

    CHANGESET_FILE_PATH = $$absolute_path("changeset.txt", $$PWD/..)
    CHANGESET = $$cat($$CHANGESET_FILE_PATH)
    QMAKE_CXXFLAGS += -DCHANGESET="$$CHANGESET"
    message("Changeset: "$$CHANGESET)

    This is qmake output;
    Project MESSAGE: Changeset: "045c99e9e492"

    And I'm trying to access CHANGESET in main.cpp like that;
    qWarning() << "CHANGESET:" << CHANGESET;

    Here is compiler error;
    <command-line>:-1: error: unable to find numeric literal operator 'operator"" c99e9e492'

    Any comment?

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

      Hi,

      You should rather use the DEFINES variable. It also requires a bit more escaping.

      CHANGESETSTR = '\\"$ ${CHANGESET}\\"'
      DEFINES += CHANGESET=\"$ ${CHANGESETSTR}\"
      

      Remove the space between the dollars, it's only so that the forum doesn't hide them

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

        Thank you very much.

        I did not tried your solution but find another one.

        This is how I declared variable at compile time;
        QMAKE_CXXFLAGS += -DCHANGESET="$$CHANGESET"

        And this is how I stringified variable in main.cpp;
        #define STRINGIZE(x) #x
        #define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
        int main(int argc, char *argv[])
        {
        qWarning() << "CHANGESET:" << STRINGIZE_VALUE_OF(CHANGESET);
        }

        I'll try your solution asap and let you know the result.
        Thanks again.

        1 Reply Last reply
        1

        • Login

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