Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Use of #if defined in C++ to select a Qt Kit

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

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 3 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • alsaA Offline
    alsaA Offline
    alsa
    wrote on last edited by alsa
    #1

    Similarly to the directive:

    #if defined(linux)
    ....
    #else
    ...
    #endif

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can't switch kits from code. It's you that defines which kit to use when you configure Qt Creator.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • yuvaramY Offline
        yuvaramY Offline
        yuvaram
        wrote on last edited by
        #3

        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 Aligeti
        Embedded Qt Developer
        : )

        alsaA 1 Reply Last reply
        2
        • yuvaramY yuvaram

          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.

          alsaA Offline
          alsaA Offline
          alsa
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved