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. MOC Bug?
QtWS25 Last Chance

MOC Bug?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.2k 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.
  • K Offline
    K Offline
    kDohmen
    wrote on last edited by kDohmen
    #1

    Hello,

    I was asking myselfe if this is a bug:

    namespace somenamespacename
    {
    #ifdef Q_OS_LINUX
      class myErrClass : public QObject
      {
      Q_OBJECT
    
      public:
        myClass();
      signals:
        void mySignal();
      }
    #endif
    
      class mySecClass : public QObject
      {
      Q_OBJECT
    
      public:
        mySecClass();
      signals:
        void mySecSignal();
      }
    }
    

    Assuming i have implemented all functions in the cpp I get an error of undefined references for myErrClass. Looking in the moc file I saw that qmake did not created the moc-content for myErrClass.

    If I remove the ifdef the content is created and everything is as expected.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Do you get the errors when Q_OS_LINUX is defined or not? Or do you get them always? Are the myErrClass functions also ifdeffed in the source file?

      (Z(:^

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kDohmen
        wrote on last edited by
        #3

        I get the error when Q_OS_LINUX is defined (compiling on Debian 7). The functions are also ifdeffed in the source file.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          OK, I've checked now and although it is not mentioned in the official MOC documentation, this tool has trouble understanding any ifdefs.

          See: "link":http://stackoverflow.com/questions/4246533/qt-signal-wrapped-in-an-ifdef and "link":http://grokbase.com/t/gg/android-qt/129q8e9fem/moc-doesnt-see-ifndef-android-guards.

          (Z(:^

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kDohmen
            wrote on last edited by
            #5

            so no bug, just not featured... ok, then I need to do a workaround... thanks :)

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              I would put it more as "known issue" - but it's been there since the dawn of time and I don't remember anybody volunteering to fix it.

              One of the problems I see is that MOC is run by qmake. But actual compilation flags are passed later - when the project is actually build. So implementing it properly in MOC is probably a big effort.

              (Z(:^

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

                Hi,

                IIRC, that's a limitation of Qt 4's moc, the Qt 5 version should work better in that aspect.

                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
                • K Offline
                  K Offline
                  kDohmen
                  wrote on last edited by
                  #8

                  I use Qt 5.3.2 so it is not only a limitation of Qt 4s moc.

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

                    Just tested with your code as a base and the minor modifications it needed to build and got no error with Qt 5.4. Can you post a complete example that fails for you ?

                    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

                    • Login

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