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
Forum Updated to NodeBB v4.3 + New Features

qmake set GCC string variable

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.3k 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 23 Nov 2015, 20:14 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 23 Nov 2015, 20:59 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 26 Nov 2015, 09:30 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

        1/3

        23 Nov 2015, 20:14

        • Login

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