Reputation: 10868
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:
static_cast
a virtual QObject
object to a A*
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?
Upvotes: 2
Views: 547
Reputation: 18218
If you really need to expose QObject
member functions through your A
and B
classes create an abstract base class (i.e. a class with only pure virtual member functions), say AbstractQObject
, and re-declare there the QObject
member functions you need to expose.
Have A
and B
derive virtually from AbstractQObject
and X
from QDialog
, A
and B
.
This should solve the problem you described, but I suspect you would be better off redesigning your code.
Upvotes: 2