[Qt-interest] Mingw/GCC via QtC for windows - Defines with spaces problem(?)

Rohan McGovern rohan.mcgovern at nokia.com
Tue Mar 3 00:20:15 CET 2009


On Tuesday 03 March 2009, ext Garth Dahlstrom wrote:
> Hi,

Hi Garth,

>
> I'm currently trying to pass an define into my application in Qt
> Creator for Windows.  I'm hitting a problem with properly
> escaping defines that have spaces in their payload.
>
> I can do this in my .pro file:
>
> DEFINES += SETTINGS_FILE=\\\".mixxx.cfg\\\"
>
> and that works.
>
> However  when I try every escaping combination I can think for
> this:
>
> DEFINES += SETTINGS_PATH=\\\"Local Settings/Application
> Data/Mixxx/\\\"
>
> I either end up with
>
> --> missing terminating " char
>
> or something mangled before it gets to gcc  (i.e.
> -DSETTINGS_PATH=\"Local -DSettings/Application -DData/Mixxx/\" )
>

I used to do it that way until I found out that the amount of
backslashes required is platform-specific.

You can try it this way.  Leave out the quotes from the define,
which means you'll be defining a bareword instead of a string:

 DEFINES += "_SETTINGS_PATH=Local\ Settings/Application\ Data/Mixxx/"

Note, the outer double quotes are to let _qmake_ know it's all
one argument, and the backslashes before the spaces are to let
_make_ know it's all one argument.

Then stringify it in your source:

#define __STRINGIFY(x) #x
#define _STRINGIFY(x) __STRINGIFY(x)
#define SETTINGS_PATH _STRINGIFY(_SETTINGS_PATH)

I don't know if that works with all compilers.

-- 
Rohan McGovern
Qt Software, Nokia



More information about the Qt-interest-old mailing list