Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to handel platform specific code in qt
Qt 6.11 is out! See what's new in the release blog

How to handel platform specific code in qt

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 16.7k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    joshua-anderson
    wrote on last edited by
    #1

    Hello,
    I am developing a multiplatform application in qt. However, I would like to have some platform specific code, like grab a few messages from the windows api.

    I obliviously don't want this code when compiling for say Linux or Mac. What is the most common way to surpress or remove code on certain platforms?

    The only time I have done this before is in unity 3d and they did it by automatically defining preprocessor defines on compile, so all you have to do is this:

    #ifdef Windows

    //windows only code here

    #else

    //code for other platforms here

    #endif

    Or

    #ifdef Linux

    // Linux only code here

    #endif

    I could use this method, but without the automatic preprocessor defines, everyone who wanted to compile it would have to manually define the platform. I was wondering of there was a more common or popular way.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi, seems you need to re-read the documentation of Qt:

      Q_OS_WIN
      Q_OS_UNIX
      Q_OS_....

      Q_CC_MSVC
      Q_CC_GNU
      Q_CC_...

      Q_PROCESSOR_X86
      Q_PROCESSOR_ARM
      Q_PROCESSOR_...

      ....

      1 Reply Last reply
      0
      • J Offline
        J Offline
        joshua-anderson
        wrote on last edited by
        #3

        What is the link to that page in the documentation? I would really like to see it. I problaby couldn't find it because it was problaby called differently then what I googled for. I looked for "platform specific defines"

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on last edited by
          #4

          http://qt-project.org/doc/qt-5.1/qtcore/qtglobal.html

          1 Reply Last reply
          0

          • Login

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