Use of #if defined in C++ to select a Qt Kit
-
Similarly to the directive:
#if defined(linux)
....
#else
...
#endifused to switch from something for Linux to something for other O.S., how can I set in C++ to switch from a Kit for Embedded System (based on OMAP Embedded to a Kit for Desktop?
#if defined(...what instruction...) ?
OR Can I add a Build Environment variable for my own use and how to use it? -
Hi,
You can't switch kits from code. It's you that defines which kit to use when you configure Qt Creator.
-
Hi,
In .pro file you can specify DEFINES as per compilers used.
linux-g++{
DEFINES+= LINUX_DESKTOP
}
win32{
DEFINES += WIN_DESKTOP
}In .cpp files you can use
#ifdef LINUX_DESKTOP
qDebug()<<"Running in Linux Desktop"<<endl;
#endif
#ifdef WIN_DESKTOP
qDebug()<<"Running in Windows Desktop"<<endl;
#endif
This should help you. -
@yuvaram
Thank you yuvaram, based on your indication I defined my own variable in one of two .pro files for my project that can be compiled using two different kits (for Dektop OR Embedded); thus, checking if it is defined or not, now I'm able to compile the version I'd like. -
Ok, so it was the other way around, enabling code depending on which platform ?
In that case you don't have to create any defines. You have the
Q_OS_XXX
defines that you can easily use in your application code.