Results 1 to 5 of 5

Thread: How to define a string in a .pro file

  1. #1
    Join Date
    Oct 2012
    Posts
    3
    Platforms
    Windows

    Default How to define a string in a .pro file

    Hi,

    I want to define a string in a .pro file. qmake is fine. When I compile the project in VS2010, the compiler complains about VERSION_STRING.

    I've tried the following and still get errors.

    DEFINES += VERSION_STRING=\\\"4.3\\\"

    DEFINES += VERSION_STRING=\\\"'4.3'\\\"

    Any help would be greatly appreciated!
    ChristineD

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to define a string in a .pro file

    defines += version_string=\"4.3\"

    Sorry for the lowercase, the forum software tries to be smarter than me.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2012
    Posts
    3
    Platforms
    Windows

    Default Re: How to define a string in a .pro file

    Thank you! That gets me past that compile issue.

    I'm wondering and trying to understand why there is a difference in how to define a constant string in the .pro file.
    Is it compiler dependent?
    Is there a QT reference that explains the syntax?

    Our original project is compiled in windows, using visual studio 2008, 32 bit, and with qt4.8.1. We define VERSION_STRING in the .pro file
    DEFINE += VERSION_STRING=\\\"4.3\\\" and are able to compile fine and access this string in the code.

    My question came up because I am compiling in windows, using visual studio 2010, 64 bit, so I compiled qt4.7.4 for 64 bit. Using the the above define created
    compiler issues but your suggestion of DEFINE += VERSION_STRING=\"4.3\" gets me past the compiler issue.

    Thanks,
    ChristineD

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to define a string in a .pro file

    The single backslash, as in C++ code, tells qmake to insert the double quote literally into the string it then places into the DEFINES variable. The value of that variable is placed literally into the Makefile that qmake later generates so that C++ compilations commands get the correct structure for the shell to execute.
    Qt Code:
    1. // In the PRO file
    2. DEFINES += -DTEST=\"value and space\"
    3. // what ends up in the Makefile
    4. DEFINES = -DTEST="value and space" -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED ...
    5. // So the shell gets this command when you run make
    6. g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DTEST="value and space" -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED ...
    To copy to clipboard, switch view to plain text mode 

    If Visual Studio causes the value to be parsed twice then you would need to double the backslashes in order to get the same end result. The pair \\ collapses to a single \, and the pair \" collapses to a double-quote.
    Qt Code:
    1. // Start with
    2. -DTEST=\\\"value and space\\\"
    3. // after first parser has reduced escaping
    4. -DTEST=\"value and space\"
    5. // after second parsing reduces escaping
    6. -DTEST="value and space"
    7. // which is what you want in your actual compiler command.
    To copy to clipboard, switch view to plain text mode 
    (The exact processing VS does is unknown to me)

  5. The following user says thank you to ChrisW67 for this useful post:


  6. #5
    Join Date
    Oct 2012
    Posts
    3
    Platforms
    Windows

    Default Re: How to define a string in a .pro file

    Thanks for your explanation! It's very helpful!

    ChristineD

Similar Threads

  1. How to define a string marco in pro file
    By jevonwang in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 6th May 2013, 05:49
  2. qmake rc file define version
    By cafu1007 in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2012, 16:38
  3. Replies: 0
    Last Post: 8th November 2011, 08:48
  4. Replies: 3
    Last Post: 8th June 2011, 06:36
  5. Replies: 1
    Last Post: 23rd May 2011, 04:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.