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 include files to qt project depending on target operating system
Forum Updated to NodeBB v4.3 + New Features

how to include files to qt project depending on target operating system

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 6.9k Views 2 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 18 May 2017, 21:22 last edited by
    #2

    Hi,

    If you have only minor changes between platforms, why not use the Q_OS_XXX macros like Q_OS_LINUX ?

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

    A 1 Reply Last reply 19 May 2017, 06:25
    1
    • S SGaist
      18 May 2017, 21:22

      Hi,

      If you have only minor changes between platforms, why not use the Q_OS_XXX macros like Q_OS_LINUX ?

      A Offline
      A Offline
      a_so
      wrote on 19 May 2017, 06:25 last edited by
      #3

      @SGaist I have never heard of these macros before. I will try it in my code but it seems a good solution for my problem at first glance. Thank you!

      J 1 Reply Last reply 19 May 2017, 06:36
      0
      • A a_so
        19 May 2017, 06:25

        @SGaist I have never heard of these macros before. I will try it in my code but it seems a good solution for my problem at first glance. Thank you!

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 19 May 2017, 06:36 last edited by J.Hilk
        #4

        @a_so

        I believe you can use these macros only inside of your classes and not in the project file itself. But I might be mistaken.

        To differ between OS inside the project file I usually use these:

        • win32
        • macx
        • unix

        eg:

        win32:DEFINES += QT_DLL
        
        macx:debug {
            HEADERS += debugging.h
        }
        
        win32|macx {
            HEADERS += debugging.h
        }
        

        Taken from the docu here:


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 19 May 2017, 06:54 last edited by
          #5

          @J-Hilk Indeed, that's the goal of these macros. The suggestion was that you don't necessarily need to have one file per platform every time there's a small change to adapt to that platform. There should be a balance between the platform specific macros in code and write platform specific files when the code is too big or too involved to fit nicely between macro guards.

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

          J 1 Reply Last reply 19 May 2017, 07:07
          1
          • S SGaist
            19 May 2017, 06:54

            @J-Hilk Indeed, that's the goal of these macros. The suggestion was that you don't necessarily need to have one file per platform every time there's a small change to adapt to that platform. There should be a balance between the platform specific macros in code and write platform specific files when the code is too big or too involved to fit nicely between macro guards.

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 19 May 2017, 07:07 last edited by
            #6

            @SGaist ah, ok, that makes total sence now. And in fact I do use those macros myself in my classes on a regular base.

            It's just the docu about qmake could really use an update!
            Just recently I searched through there to find out, how to automatically link precompiled libaries depending on the compiler set/used for my project.

            Eventually I found that information, but it took way to long to find, for such an easy solution.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 19 May 2017, 08:16 last edited by
              #7

              Documentation can always be improved ;)

              If you find something unclear or hard to find, you can contribute an update that will make everyone's life easier. All the documentation is within Qt source tree so you're welcome to improve it and submit a patch :)

              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
              • A Offline
                A Offline
                a_so
                wrote on 19 May 2017, 11:10 last edited by
                #8

                So far I tried the Q_OS_xxx Macros within my source and header files. It works fine! Thank you!
                However, qmake recognizes my host OS (Linux) before it actually catches that my target OS is Android. I moved Bonjour related files into the .pri files and therefore these files are added to the project although I do not want them there.
                I will try the solution from @J-Hilk the next days. I think it can solve my problems.

                I am curious, how can I remove files from a project within my .pri files?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 19 May 2017, 11:37 last edited by SGaist
                  #9

                  Remove ? Usually you use scopes in your .pro or .pri file to add files to build for the platforms you are currently working on.

                  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
                  • A Offline
                    A Offline
                    a_so
                    wrote on 22 May 2017, 06:26 last edited by
                    #10

                    My solution is:
                    I added all header and source files in the .pro file and for Android I removed conflicting files in android.pri file with

                    HEADERS -= ...
                    SOURCES -= ...
                    

                    Thanks a lot for your solutions!

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 22 May 2017, 06:52 last edited by
                      #11

                      That's pretty counter intuitive and a maintenance nightmare in the making.

                      Why not just have a scope in your .pro files that includes your android specific files when working on the android platform and the other files in the else statement ? i.e.

                      android {
                          SOURCES += android_stuff.cpp
                          HEADERS += something.h
                      } else {
                          SOURCES += other_stuff.cpp
                          HEADERS += something_else.h
                      }
                      

                      From a maintainer point of view, removing files from the build system really doesn't make sense.

                      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

                      11/11

                      22 May 2017, 06:52

                      • Login

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