Reputation: 2413
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)
{
}
};
Upvotes: 5
Views: 2004
Reputation: 11
in this case you need just to try inherit the QObject First, I mean:
Remember that "Multiple Inheritance Requires QObject to Be First", otherwise you'll get either the same error as above, or something along the lines of "YourClass inherits from two QObject subclasses" from the moc.
See this link! for more information.
for example:
#include<QObject>
#include<QGraphicsEllipseItem>
class myclass : public QObject , public QGraphicsEllipseItem{
Q_OBJECT
// your code...
};
Upvotes: 1
Reputation: 12321
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.
Upvotes: 1
Reputation: 4838
i had a similar error when inheriting from QRunnable which by the the way is NOT a QObject.
Cause
Upvotes: 1
Reputation: 4159
QGraphicsEllipseItem is not QObject, so just remove Q_OBJECT from class declaration.
Upvotes: 8