PDA

View Full Version : Inheritance confusion - which class made inheritating from QObject



kornicameister
23rd December 2010, 00:42
I have two singular classes and one set of classes which inherit from one of these two mentioned before.

So I have
(partly) abstract class A(public common methods and some variables), and abstract class B (includes only four methods pure virtual)
those two are not linked in any way (and for now none of them inherits QObject)
going on to the set
these classes inherit A and B mostly, but two of them does not require it.

I am familiar that I can not make multiple inheritance from QObject... so I would like to ask where to put "single" inheritance statement and all additional stuff such as appropriate macros and so on ?
For now all classes from set includes inheritance from QObject... but maybe it would be better to push it (QObject and all related stuff) to class A, because every class in set uses it, except to class B

wysota
23rd December 2010, 10:54
Do I understand correctly that you have two classes that inherit just A or just B and a bunch of classes that inherit both A and B? If so then if you don't need QObject at the level of A or B then if you need QObject at the level of those subclasses then inherit QObject in your bottom-most class. Just remember QObject has to go first.


class MyClass: public QObject, public A, public B {
Q_OBJECT
//...
};