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 does not run if Q_OBJECT macro defined in another macro
Forum Updated to NodeBB v4.3 + New Features

moc does not run if Q_OBJECT macro defined in another macro

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 779 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.
  • P Offline
    P Offline
    Patrick Wright
    wrote on last edited by
    #1

    I am attempting to write some code which can be easily ported away from using Qt. To do so, I am wrapping the Q_OBJECT macro inside my own macro as so

    #define MY_OBJECT(...) Q_OBJECT
    
    using MyObject = QObject;
    

    Which gets used as follows:

    class Example : public MyObject {
    MY_OBJECT(Example)
    };
    

    If I run the moc manually on this file, everything works well. However, when I attempt to compile this code using Qt Creator, it does not event attempt to run the moc for this file. And thus the compilation fails due to missing function definitions.

    What do I need to do to get this to work?

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

      Hi,

      Did you force a re-run of qmake after changing your header ?

      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
      • P Offline
        P Offline
        Patrick Wright
        wrote on last edited by
        #3

        Yes. I even tried deleting the entire build folder an re-generating it. I looked at the "Compile Output" logs and I do not see the moc being called for the file at all.

        As a comparison, I simple added Q_OBJECT to one of the files which was using MY_OBJECT. Once I did this, the moc_*.cpp file was generated properly.

        I am using Qt creator 6.0.1 with Qt 5.15.2 if that helps.

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

          After some reflection, I am wondering whether moc can expand your macro properly.

          I remember there was a limitation related to macro expansion that was lifted for Qt 5 but I don't remember whether it applied to your case.

          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
          • P Offline
            P Offline
            Patrick Wright
            wrote on last edited by
            #5

            If that's the case, since I am only really using signals in the code I want to be "portable", is there a way to generate the signal boilerplate code without using the Q_OBJECT macro (and thus without using the moc)?

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

              Yes, there's Woboq's Verdigris.

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

                QtCreator is just a wrapper around running the relevant build tools. Are you using qmake or CMake in your QtCreator build kit?

                If it is qmake, is the relevant header file in qmake's HEADERS variable?

                If CMake, perhaps AUTOMOC is not working because it does not see the magic "Q_OBJECT". The docs seem to describe exactly the sort of "hidden" Q_OBJECT scenario you have. You can define the AUTOMOC_MACRO_NAMES variable to tweak what it looks for.
                https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html#automoc

                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