Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Moc issue with osX/iOs application
Qt 6.12 LTS is out! See what's new in the release blog

Moc issue with osX/iOs application

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
18 Posts 3 Posters 10.1k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #6

    Well, you don't need them since Qt already provides defines for the platform it supports so you only have to use

    #if defined(Q_OS_MACOS)
    #elif defined(Q_OS_IOS)
    #endif
    

    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
    • N Offline
      N Offline
      NAnder
      wrote on last edited by
      #7

      I have tried, but I have the same issue with moc in qmake if I use Q_OS_MACOS and Q_OS_IOS : moc only use the code where Q_OS_MACOS is define whatever I ask it to build, an iOs project or an OsX project.

      All my class depending of #if defined(Q_OS_IOS) got the warning message :

      Note: No relevant classes found. No output generated.
      

      Is it the normal qmake/moc behaviour or I do something bad ?

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

        Can you post the code that triggers that ?

        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
        • N Offline
          N Offline
          NAnder
          wrote on last edited by
          #9

          Hi, sorry for the late answer. I got some issues.
          Here is smallest set of code to sample that show the problem:
          project.pro

          QT       += core gui
          
          TARGET = Bugs
          TEMPLATE = app
          
          SOURCES += main.cxx
          HEADERS += test_ios.hxx test_osx.hxx
          

          main.cxx

          #include <QApplication>
          #include "test_ios.hxx"
          #include "test_osx.hxx"
          
          Tests::Tests() {}
          Tests::~Tests() {}
          //#include <TargetConditionals.h>
          #ifdef Q_OS_IOS
          //#if TARGET_OS_SIMULATOR || TARGET_OS_IPHONE
          void Tests::Hello() {}
          #endif
          
          int main(int argc, char * argv[])
          {
            Tests bug;
            return 0;
          }
          

          test_ios.hxx

          #include <QApplication>
          #ifdef __APPLE__
          //# include <TargetConditionals.h>
          //# if TARGET_OS_SIMULATOR || TARGET_OS_IPHONE
          #  ifdef Q_OS_IOS
          
          #  include <QObject>
          
          class Tests : public QObject
          {
            Q_OBJECT
          
          public:
            explicit Tests();
            ~Tests();
          
            void Hello();
          };
          
          # endif
          #endif
          

          test_osx.hxx

          #include <QApplication>
          #ifdef __APPLE__
          # include <TargetConditionals.h>
          //# if TARGET_OS_OSX
          #ifdef Q_OS_MACOS
          
          #  include <QObject>
          
          class Tests : public QObject
          {
            Q_OBJECT
          
          public:
            explicit Tests();
            ~Tests();
          };
          
          # endif
          #endif
          

          I create the Xcode project with :

          Qt5.9.1/5.9.1/ios/bin/qmake ../project.pro
          

          Best regards

          kshegunovK 1 Reply Last reply
          0
          • N NAnder

            Hi, sorry for the late answer. I got some issues.
            Here is smallest set of code to sample that show the problem:
            project.pro

            QT       += core gui
            
            TARGET = Bugs
            TEMPLATE = app
            
            SOURCES += main.cxx
            HEADERS += test_ios.hxx test_osx.hxx
            

            main.cxx

            #include <QApplication>
            #include "test_ios.hxx"
            #include "test_osx.hxx"
            
            Tests::Tests() {}
            Tests::~Tests() {}
            //#include <TargetConditionals.h>
            #ifdef Q_OS_IOS
            //#if TARGET_OS_SIMULATOR || TARGET_OS_IPHONE
            void Tests::Hello() {}
            #endif
            
            int main(int argc, char * argv[])
            {
              Tests bug;
              return 0;
            }
            

            test_ios.hxx

            #include <QApplication>
            #ifdef __APPLE__
            //# include <TargetConditionals.h>
            //# if TARGET_OS_SIMULATOR || TARGET_OS_IPHONE
            #  ifdef Q_OS_IOS
            
            #  include <QObject>
            
            class Tests : public QObject
            {
              Q_OBJECT
            
            public:
              explicit Tests();
              ~Tests();
            
              void Hello();
            };
            
            # endif
            #endif
            

            test_osx.hxx

            #include <QApplication>
            #ifdef __APPLE__
            # include <TargetConditionals.h>
            //# if TARGET_OS_OSX
            #ifdef Q_OS_MACOS
            
            #  include <QObject>
            
            class Tests : public QObject
            {
              Q_OBJECT
            
            public:
              explicit Tests();
              ~Tests();
            };
            
            # endif
            #endif
            

            I create the Xcode project with :

            Qt5.9.1/5.9.1/ios/bin/qmake ../project.pro
            

            Best regards

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #10

            You're running moc on an empty header (either one of the two is, or both are, empty). So moc complains about not having any class to parse.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NAnder
              wrote on last edited by
              #11

              Hi, thx for your answer.
              Yes it should complain about one empty header, that would not be an issue.
              But it complain about the wrong one, when i try compile for iOs, why it say :

              Note: No relevant classes found. No output generated.
              

              about test_ios.hxx

              kshegunovK 1 Reply Last reply
              0
              • N NAnder

                Hi, thx for your answer.
                Yes it should complain about one empty header, that would not be an issue.
                But it complain about the wrong one, when i try compile for iOs, why it say :

                Note: No relevant classes found. No output generated.
                

                about test_ios.hxx

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #12

                My guess would be that __APPLE__ isn't defined.

                Read and abide by the Qt Code of Conduct

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

                  Rather than having empty headers, just don't try to build that class if it doesn't make sense on a given platform.

                  Use scopes in your .pro file to only compile what is needed.

                  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
                  • N Offline
                    N Offline
                    NAnder
                    wrote on last edited by NAnder
                    #14

                    Hi, thx for the answer.

                    __ APPLE__ is defined otherwise test_osx.hxx would generate an empty moc file too, which is not the case.

                    Yes using scope in .pro file is the way to avoid useless warning, but I not used it here because I wanted to show that moc only generate a moc file from test_osx.hxx whatever I ask qmake to generate a project for OsX or iOs.

                    My question is it the normal moc behaviour to expand only OSX macro when I ask qmake to generate a project for iOs ? If not, why it do it with my sample ?

                    Best regards,

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

                      For me it generates an empty moc file also for iOS when building for macOS and that's expected. Since you are passing both files to the HEADERS variable moc will be run on both generating an empty file for the other OS since the macro is correctly handled.

                      To have a truly cross-platform code base, use scopes in your .pro file and only include what's relevant to the platform in your source code otherwise it will become quiet quickly a nightmare to maintain.

                      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
                      2
                      • N Offline
                        N Offline
                        NAnder
                        wrote on last edited by NAnder
                        #16

                        Hi,

                        Thank you for the answers.

                        It took me sometime for write back, because i was training my english to be able to answer here. My question is very clear in my head, but it seems my words are bad.

                        Yes it's generate an empty moc class warning when i compile for mac osX. This is not an issue, first it just a warning, the compilation still go on, and like you said fix the warning is very easy.

                        My question was, why it not work when i try compile for iOS. When i try, I got a warning about test_ios.hxx generating an empty file. And that is a critical error because the compiler will not be able to find the iOS code. Moc seems not expand IOS macro, but always OSX macro whenever it's an OSx or IOs build.

                        Best regards,

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

                          Can you check whether it's still the case with more recent version of Qt ?

                          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
                          • N Offline
                            N Offline
                            NAnder
                            wrote on last edited by
                            #18

                            Thank a lot for the answer.
                            I'll try as soon I can.

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