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. Q_OBJECT macro generation
QtWS25 Last Chance

Q_OBJECT macro generation

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 735 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.
  • michalt38M Offline
    michalt38M Offline
    michalt38
    wrote on last edited by michalt38
    #1

    I have read that when Q_OBJECT macro is placed inside a class, some meta-object code is generated. Is this code generated as body of the Q_OBJECT macro? What's more does the generated code provide a signal/slot mechansim for a class in general or only for user-defined signals and slots?

    jsulmJ 1 Reply Last reply
    0
    • michalt38M michalt38

      I have read that when Q_OBJECT macro is placed inside a class, some meta-object code is generated. Is this code generated as body of the Q_OBJECT macro? What's more does the generated code provide a signal/slot mechansim for a class in general or only for user-defined signals and slots?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @michalt38 said in Q_OBJECT macro generation:

      Is this code generated as body of the Q_OBJECT macro?

      No, moc generates additional source code files, see https://doc.qt.io/qt-5/why-moc.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • michalt38M Offline
        michalt38M Offline
        michalt38
        wrote on last edited by
        #3

        So what is the body of the Q_OBJECT doing?

        mrjjM 1 Reply Last reply
        0
        • michalt38M michalt38

          So what is the body of the Q_OBJECT doing?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @michalt38
          It expands to this
          Basically it inserts a static MetaObject.

          #define Q_OBJECT \
          public: \
              QT_WARNING_PUSH \
              Q_OBJECT_NO_OVERRIDE_WARNING \
              static const QMetaObject staticMetaObject; \
              virtual const QMetaObject *metaObject() const; \
              virtual void *qt_metacast(const char *); \
              virtual int qt_metacall(QMetaObject::Call, int, void **); \
              QT_TR_FUNCTIONS \
          private: \
              Q_OBJECT_NO_ATTRIBUTES_WARNING \
              Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
              QT_WARNING_POP \
              struct QPrivateSignal {}; \
              QT_ANNOTATE_CLASS(qt_qobject, "")
          
          1 Reply Last reply
          2
          • michalt38M Offline
            michalt38M Offline
            michalt38
            wrote on last edited by michalt38
            #5

            Thanks. Is the code that moc generates used to handle the user-defined signals and slots only or the whole signal/slot mechanism in general?

            mrjjM 1 Reply Last reply
            0
            • michalt38M michalt38

              Thanks. Is the code that moc generates used to handle the user-defined signals and slots only or the whole signal/slot mechanism in general?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @michalt38
              For signal and slot in general.

              However, its now a slight grey area with the new pointer to method based connect syntax as
              i think you can skip the Q_OBJECT now if you dont have any custom signals.
              And you dont have to flag a slot with the slot macro anymore to use it as any member method can now be used as a slot. with the "new" connect syntax.

              1 Reply Last reply
              1

              • Login

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