Hi Sean, Den 13-11-2015 kl. 02:51 skrev Murphy, Sean:
I'm trying to add a defined string in my .pro file to be inserted by the preprocessor at compile time and I'm having trouble when it has spaces in it. Here's a really simplistic example: [...] But if I want my text to be a little more interesting and have spaces in it, it fails. Changing the DEFINES line in the .pro to: DEFINES += MY_STRING=\\\"Hello You\\\" refuses to compile: g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DMY_STRING=\"Hello -DYou\" -DQT_CORE_LIB -I..\testDefinesWithSpacesConsole -I"..\..\..\..\Qt_5_3_2\5.3\mingw482_32\include" -I"..\..\..\..\Qt_5_3_2\5.3\mingw482_32\include\QtCore" -I"debug" -I"." -I"..\..\..\..\Qt_5_3_2\5.3\mingw482_32\mkspecs\win32-g++" -o debug\main.o ..\testDefinesWithSpacesConsole\main.cpp <command-line>:0:11: warning: missing terminating " character [enabled by default] <command-line>:0:4: warning: missing terminating " character [enabled by default] <command-line>:0:4: warning: missing whitespace after the macro name [enabled by default] ..\testDefinesWithSpacesConsole\main.cpp:8:5: error: missing terminating " character qDebug() << QString(MY_STRING); ^ Makefile.Debug:190: recipe for target 'debug/main.o' failed mingw32-make[1]: *** [debug/main.o] Error 1So you can see that the string "Hello You" that I was trying to pass intact has now been split up into two different defines. Is there a way to get this to work?
My recommendation would be to go in a different direction. The only time I do stuff like this is when I add 3rd party code into my build trees. If this is your situation, then you probably have to do it.
If you can avoid this situation, put the possible set of defines in a file instead and make your DEFINES choose from the set.
If not, you can always add the c++ compile flag yourself. You don't have to use DEFINES, this is just a compiler agnostic way of adding defines. Of course, you would have to do this for every compiler you use, but these days that's usually max three.
Bo Thorsen, Director, Viking Software. -- Viking Software Qt and C++ developers for hire http://www.vikingsoft.eu _______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
