I want to implement custom behavior for certain objects.
To do this, let my objects (inheriting from QGraphicsItem) implement some interface.
class SomeParentItem { SomeParentItem(bool x) { x = true; } void function1() {} }; class SomeInterface { virtual void function2() = 0; }; class XYZItem : public QGraphicsXYZItem, public SomeParentItem, public SomeInterface { XYZItem(bool x):SomeParentItem(x) {} virtual void function2() { x = false; } }; class MPQItem : public QGraphicsMPQItem, public SomeParentItem { MPQItem (bool x):SomeParentItem(x) {} };
From the outside, I thought I was just doing
SomeInterface* item1 = dynamic_cast<SomeInterface*>(item); if(item1 == NULL) item->function1(); else item1->function2();
Unfortunately, this is a failure ... usually ... therefore I created a flag for verification, and if the flag was true, then only dared to drop it.
But I kept thinking, he should not fail. So I became bold and tried again, this time at QWidget. Instead of a crash, I got
QWidget::insertAction: Attempt to insert null action
This is an if(item1 == NULL) test that gives this message ...
How to check if my element SomeInterface ?
Note: item cannot be null.
c ++ inheritance multiple-inheritance qt
Thalia
source share