Problems with object design, how to get over ambiguous warnings.
-
In my original design I have created classes with are derived from Qt base widget classes and these derived classes have a common node member.
Now I am changing the design as there are elements in the node which would benefit if the node class was a base class with pure virtual functions that would be defined in the derived widget classes.
For example, originally:
class clsQtPushBtn : public QPushButton { Q_OBJECT friend class clsXMLnode; private: clsXMLnode* mpobjNode; ...
Now, the new design is cleaner and more powerful:
class clsQtPushBtn : public QPushButton, clsXMLnode { Q_OBJECT ...
The issue I'm getting now is when I try to compile I see:
moc_clsQtPushBtn.cpp:78:21: error: ambiguous conversion from derived class 'const clsQtPushBtn' to base class 'QObject': class clsQtPushBtn -> class QPushButton -> class QAbstractButton -> class QWidget -> class QObject class clsQtPushBtn -> class clsXMLnode -> class QObject return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; ^~~~~ moc_clsQtPushBtn.cpp:78:50: error: ambiguous conversion from derived class 'const clsQtPushBtn' to base class 'QObject': class clsQtPushBtn -> class QPushButton -> class QAbstractButton -> class QWidget -> class QObject class clsQtPushBtn -> class clsXMLnode -> class QObject return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; ^~~~~
Is there anyway to solve this?
One possible cause could be that in the original design which I haven't change yet:
class clsXMLnode : public QObject { Q_OBJECT ....
Would removing Q_OBJECT and not deriving from QObject help?
-
@SPlatten said in Problems with object design, how to get over ambiguous warnings.:
Thanks, I think I'll have to keep the original design and look for another way to simplify things.
Aggregate instead. Your button isn't a node to begin with, so here the multiple inheritance is even ideologically wrong. If you have a class
Car
it shouldn't inherit fromSteeringWheel
andEngine
, the car is not an engine, nor is it a steering wheel. It has an engine on the other hand. -
You simply can't derive from QObject two times - fix your design.