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:
test.pro:
QT += core
QT -= gui
TARGET = testDefinesWithSpacesConsole
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
DEFINES += MY_STRING=\\\"Hello\\\"
SOURCES += main.cpp
And main.cpp:
#include <QCoreApplication>
#include <QString>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << QString(MY_STRING);
return a.exec();
}
This works as expected, running the application prints Hello on the command
line.
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 1
So 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?
Sean
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest