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. [SOLVED] Convert #define value to QString?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Convert #define value to QString?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 6 Posters 10.5k 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on 17 Feb 2012, 13:43 last edited by
    #1

    I have the following define in a central .pri file:

    @DEFINES += "TCL_VERSION=0.75"@

    In my program, I would like to output this version, and therefore need to convert the value '0.75' into a QString.

    No obvious way to do that occurred to me. QString(TCL_VERSION) does not compile, and QString("TCL_VERSION") will obviously not do what I want.

    Ideas?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on 17 Feb 2012, 13:50 last edited by
      #2

      You either modify your .pri file and wrap the value correctly with quotes
      @
      DEFINES += TCL_VERSION="\"0.75\""

      QString(TCL_VERSION);
      @
      or you use the preprocessor to do this for you
      @
      #define QUOTE(string) _QUOTE(string)
      #define _QUOTE(string) #string

      QString(QUOTE(TCL_VERSION));
      @

      B 1 Reply Last reply 6 Mar 2021, 12:23
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on 20 Feb 2012, 07:39 last edited by
        #3

        Thanks!

        On an unrelated note: Why do I always get
        "Error Message: Unable to receive your submission at this time " whenever I try to just write "Thanks"?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on 20 Feb 2012, 08:00 last edited by
          #4

          [quote author="Asperamanca" date="1329723547"]Thanks!

          On an unrelated note: Why do I always get
          "Error Message: Unable to receive your submission at this time " whenever I try to just write "Thanks"?[/quote]

          Network problem?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Asperamanca
            wrote on 20 Feb 2012, 08:01 last edited by
            #5

            Nope. It consistently happens when I try to write short answers.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on 20 Feb 2012, 09:11 last edited by
              #6

              I think there is a minimum amount of characters which need to be entered into a post to be accepted (to prevent short bump and spam posts). The error message is just misleading.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on 20 Feb 2012, 10:53 last edited by
                #7

                Additionally, you cannot post a comment that has the very same wording as a comment posted previously. If someone else had posted "Nope. It consistently happens when I try to write short answers." before, you wouldn't have been able to send your comment too.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • L lgeyer
                  17 Feb 2012, 13:50

                  You either modify your .pri file and wrap the value correctly with quotes
                  @
                  DEFINES += TCL_VERSION="\"0.75\""

                  QString(TCL_VERSION);
                  @
                  or you use the preprocessor to do this for you
                  @
                  #define QUOTE(string) _QUOTE(string)
                  #define _QUOTE(string) #string

                  QString(QUOTE(TCL_VERSION));
                  @

                  B Offline
                  B Offline
                  bogdan_bdg
                  wrote on 6 Mar 2021, 12:23 last edited by bogdan_bdg 3 Jun 2021, 13:10
                  #8

                  @lgeyer

                  You [...] modify your .pri file and wrap the value correctly with quotes
                  @
                  DEFINES += TCL_VERSION=""0.75""

                  QString(TCL_VERSION);
                  @

                  Is this still valid? I get unknown type name '<my define string>' when I follow the advice on Qt 5.15.x

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bogdan_bdg
                    wrote on 6 Mar 2021, 13:09 last edited by
                    #9

                    The preprocessor "stringification" works though.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 6 Mar 2021, 19:02 last edited by
                      #10

                      Hi,

                      It would be simpler to use a generated header. The double quote escaping won't work on all platforms.

                      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