Important: Please read the Qt Code of Conduct -

How to handel platform specific code in qt

  • 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


    //code for other platforms here



    #ifdef Linux

    // Linux only code here


    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.

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





  • 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"

Log in to reply