Important: Please read the Qt Code of Conduct -

Use of #if defined in C++ to select a Qt Kit

  • Similarly to the directive:

    #if defined(linux)

    used 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?

  • Lifetime Qt Champion


    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.

    In .cpp files you can use
    #ifdef LINUX_DESKTOP
    qDebug()<<"Running in Linux Desktop"<<endl;
    #ifdef WIN_DESKTOP
    qDebug()<<"Running in Windows Desktop"<<endl;
    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.

  • Lifetime Qt Champion

    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.

Log in to reply