I need to use multiple inheritance because I need to (1) implement an 'is-a' relationship from QGraphicsItem, and (2) implement an application-specific interface (MyInterface):
@class MyClass : public QGraphicsTextItem, public MyInterface@
ROOT supports its own version of the signal/slot communication mechanism originally featured in Qt, a C GUI application framework by Troll Tech. The ROOT implementation uses the ROOT type system. In addition to all features provided by Qt the ROOT version supports connecting slots to a class (as opposed to connecting to a specific object). How to connect an abstract signal to a slot within the interface's constructor? Generally speaking, interfaces should be abstract classes, and their constructors shouldn't be doing anything at all. So this is bad design.
I would like to connect to signals from pointers to the interface, i.e.:
@MyInterface *my_interface_instance = GetInstance();
connect(my_interface_instance, SIGNAL(MyInterfaceSignal()), this, SLOT(SomeSlot()));@
Problem: To expose signals in MyInterface, it needs to derive from QObject. But then I have multiple-inheritance from QObject, which is not allowed. The solutions on 'this article':http://doc.trolltech.com/qq/qq15-academic.html are IMO fairly useless in the common case (accessing an object through its interface), because you cannot connect the signals and slots from MyInterface* but must cast it to the derived-type. Since MyClass is one of many MyInterface-derived classes, this would necessitate 'code-smelly' if-this-cast-to-this-else-if-that-cast-to-that statements and defeats the purpose of the interface.
The solution below seems to work, but I was hoping a Troll could let me know if this is supported or is going to cause undefined behavior. If I dynamic_cast a MyInterface* to QObject* (because I know all MyInterface-derived classes also inherit eventually from QObject), it seems to work:
Qt Signal Slots

Qt Signal Slot With 2 Arguments
@class MyInterface {
protected:
virtual void MyInterfaceSignal() = 0;
};
class MyClass : public QGraphicsTextItem, public MyInterface {
Q_OBJECT
signals:
void MyInterfaceSignal();
};
@
Usage:
@MyInterface my_interface_instance = GetInstance();
connect(dynamic_cast<QObject>(my_interface_instance), SIGNAL(MyInterfaceSignal()), this, SLOT(SomeSlot()));@
Qt Signal Slot Thread
Is this a bad idea?