Interfaces must inherit QObject?!
-
@kshegunov
Is that a requirement of C++? The OP claimedclass VictoriaSpongeCake : public ICake, public QObjectSo if I change
ICaketo inherit like this:class ICake: public QObjectIt all compiles without a problem.
That is not quoting me, it is quoting him.
@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) -
@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)@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... ;-) -
@kshegunov
Is that a requirement of C++? The OP claimedclass VictoriaSpongeCake : public ICake, public QObjectSo if I change
ICaketo inherit like this:class ICake: public QObjectIt all compiles without a problem.
That is not quoting me, it is quoting him.
@JonB said in Interfaces must inherit QObject?!:
@kshegunov
Is that a requirement of C++? The OP claimedclass VictoriaSpongeCake : public ICake, public QObjectSo if I change
ICaketo inherit like this:class ICake: public QObjectIt 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 makingICakeinherit QObject and adding theQ_OBJECTmacro.@JonB said in Interfaces must inherit QObject?!:
How then can the OP here arrange to write an "interface" which inherits from
QObjectand 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
-
@JonB said in Interfaces must inherit QObject?!:
@kshegunov
Is that a requirement of C++? The OP claimedclass VictoriaSpongeCake : public ICake, public QObjectSo if I change
ICaketo inherit like this:class ICake: public QObjectIt 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 makingICakeinherit QObject and adding theQ_OBJECTmacro.@JonB said in Interfaces must inherit QObject?!:
How then can the OP here arrange to write an "interface" which inherits from
QObjectand 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