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. Interfaces must inherit QObject?!
Forum Updated to NodeBB v4.3 + New Features

Interfaces must inherit QObject?!

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 5 Posters 5.1k Views 3 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.
  • JonBJ JonB

    @kshegunov
    Is that a requirement of C++? The OP claimed

    class VictoriaSpongeCake : public ICake, public QObject
    

    So if I change ICake to inherit like this:

    class ICake: public QObject
    

    It all compiles without a problem.

    That is not quoting me, it is quoting him.

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

    @JonB said in Interfaces must inherit QObject?!:

    Is that a requirement of C++?

    It is not a requirement, but there's a significant difference.
    Here's links, I know you love them sources:
    https://isocpp.org/wiki/faq/multiple-inheritance (What is the “dreaded diamond”? being key)
    https://en.cppreference.com/w/cpp/language/derived_class (Virtual base classes is relevant)

    Read and abide by the Qt Code of Conduct

    JonBJ 1 Reply Last reply
    3
    • kshegunovK kshegunov

      @JonB said in Interfaces must inherit QObject?!:

      Is that a requirement of C++?

      It is not a requirement, but there's a significant difference.
      Here's links, I know you love them sources:
      https://isocpp.org/wiki/faq/multiple-inheritance (What is the “dreaded diamond”? being key)
      https://en.cppreference.com/w/cpp/language/derived_class (Virtual base classes is relevant)

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #22

      @kshegunov
      Yeah, thanks, this looks good. public virtual Base, that's a new one for me, I like it. The more complexity in C++ the better... ;-)

      1 Reply Last reply
      1
      • JonBJ JonB

        @kshegunov
        Is that a requirement of C++? The OP claimed

        class VictoriaSpongeCake : public ICake, public QObject
        

        So if I change ICake to inherit like this:

        class ICake: public QObject
        

        It all compiles without a problem.

        That is not quoting me, it is quoting him.

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by JKSH
        #23

        @JonB said in Interfaces must inherit QObject?!:

        @kshegunov
        Is that a requirement of C++? The OP claimed

        class VictoriaSpongeCake : public ICake, public QObject
        

        So if I change ICake to inherit like this:

        class ICake: public QObject
        

        It all compiles without a problem.

        That is not quoting me, it is quoting him.

        OP forgot to re-run qmake (or delete the build directory) after making ICake inherit QObject and adding the Q_OBJECT macro.

        @JonB said in Interfaces must inherit QObject?!:

        How then can the OP here arrange to write an "interface" which inherits from QObject and apply it to classes which inherit from QObject too?

        They can't.

        QObjects are designed to be "identity objects", as opposed to "value objects": https://doc.qt.io/qt-5/object.html#qt-objects-identity-vs-value (for example, an image is a value but a window is an identity). I'd say that an "interface object" is neither an identity nor a value.

        One more thought: If a class inherits from 2 differnent QObjects, what should obj->staticMetaObject.superClass() return?

        P.S. I think you'll enjoy the thoroughness of this article: https://www.ics.com/blog/multiple-inheritance-qt

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        JonBJ 1 Reply Last reply
        2
        • JKSHJ JKSH

          @JonB said in Interfaces must inherit QObject?!:

          @kshegunov
          Is that a requirement of C++? The OP claimed

          class VictoriaSpongeCake : public ICake, public QObject
          

          So if I change ICake to inherit like this:

          class ICake: public QObject
          

          It all compiles without a problem.

          That is not quoting me, it is quoting him.

          OP forgot to re-run qmake (or delete the build directory) after making ICake inherit QObject and adding the Q_OBJECT macro.

          @JonB said in Interfaces must inherit QObject?!:

          How then can the OP here arrange to write an "interface" which inherits from QObject and apply it to classes which inherit from QObject too?

          They can't.

          QObjects are designed to be "identity objects", as opposed to "value objects": https://doc.qt.io/qt-5/object.html#qt-objects-identity-vs-value (for example, an image is a value but a window is an identity). I'd say that an "interface object" is neither an identity nor a value.

          One more thought: If a class inherits from 2 differnent QObjects, what should obj->staticMetaObject.superClass() return?

          P.S. I think you'll enjoy the thoroughness of this article: https://www.ics.com/blog/multiple-inheritance-qt

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #24

          @JKSH said in Interfaces must inherit QObject?!:

          OP forgot to re-run qmake (or delete the build directory) after making ICake inherit QObject and adding the Q_OBJECT macro.

          They can't.

          Thank you, this makes a lot more sense then!

          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