I was trying to inherit from QGraphicsEllipseItem 'cause i wanted to add some functionality to it. However i was faced with this error, which probably has something to do with the compiler/precompiler or moc?
error: 'staticMetaObject' is not a member of 'QGraphicsEllipseItem'
And here's the class code:
class MyEllipseItem : public QGraphicsEllipseItem
{
Q_OBJECT
public:
MyEllipseItem (const QRectF & outline) : QGraphicsEllipseItem(outline)
{
}
};
QGraphicsEllipseItem is not QObject, so just remove Q_OBJECT from class declaration.
i had a similar error when inheriting from QRunnable which by the the way is NOT a QObject.
Cause
If however you need to use some slots/signals in your class you could inherit from QObject as well like the QGraphicsObject does
class MyEllipseItem : public QGraphicsEllipseItem, public QObject
{
Q_OBJECT
public:
MyEllipseItem (const QRectF & outline) : QGraphicsEllipseItem(outline)
{
}
};
It may be a better idea to inherit from QGraphicsObject
and reimplement the ellipse drawing.
For more details check the QGraphicsObject documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With