Using Visual Studio on a Qt project (with the Qt addon), seems to always throw up an error message:
error C2001: newline in constant
From the following line:
this->setApplicationVersion(QString(BUILD_VERSION));
or whenever I use a compiler constant defined in my QMake file. BUILD_VERSION is defined in my QMake build recipe, compiling the project works successfully if I use a different IDE (even when I use the same MSVC compiler, everything works).
I imagine I’m either missing a preference in the Qt addon or inside Visual Studio, or I need to redefine my constant’s outside of my QMake files etc…
The constant is defined and picked up by Intellisense as:
#define BUILD_VERSION \"0.1.0\"
Found the issue is down to escaping the quotes in the constant, in Visual Studio this won’t work but it will work with Mingw, and the MSVC compiler on the command line. Defining constants without the escaping works with Visual Studio:
#define BUILD_VERSION "0.1.0"
The problem is to define the constants in the QMake file, I need to escape like:
#define BUILD_VERSION \\\"0.1.0\\\"
Is there a way to define them in the QMake file and keep them working with Visual Studio?
consider writing
where
TO_STRINGconverts a something to string:i don’t have QMake but I gather that the problem is that QMake does a
TO_STRING-like operation, and then also doing it yourself, as I noted first, is a general solution.EDIT: @sixones asks in a follow up comment,
The problem is apparently that the macro passed as argument is defined as nothing (not undefined, but defined as nothing).
A solution is to use a C99/C++11 variadic macro definition, as follows: