I have multiple QObject subclasses which should act as interface classes and be implemented by (inherited by) some other classes. For example let class A : virtual public QObject
and class B : virtual public QObject
be interface classes. I need a QDialog
object to implement their behavior like: class X: public QDialog, A, B
.
Unfortunately I did not read documentation carefully at design time and now I realized two facts:
- implementing slots as pure virtual member functions is not possible because moc-generated code will need to call them.
- Multiple inheritance is not supported for QObject-derived classes. That's not a diamond thing. It's because moc-generated code can't
static_cast
a virtualQObject
object to aA*
via virtual base. (That's what compiler says!)
What is best possible alternative design to which affects code as less as possible? I can think of macro hacks. Maybe a macro in base class (like Q_OBJECT
) to copy all members, signals, slots of base to derived class?
Note That's really bad that QObject
s can't be inherited multiple times. Isn't?