Qt inherits from QGraphicsEllipseItem

I tried to inherit from QGraphicsEllipseItem because I wanted to add some features to it. However, I came across this error, which probably has something to do with the compiler / precompiler or moc?

error: 'staticMetaObject' is not a member of 'QGraphicsEllipseItem'

And here is the class code:

class MyEllipseItem : public QGraphicsEllipseItem
{
    Q_OBJECT

public:
    MyEllipseItem (const QRectF & outline) : QGraphicsEllipseItem(outline)
    {

    }
};
+5
source share
4 answers

QGraphicsEllipseItem is not a QObject, so just remove Q_OBJECT from the class declaration.

+8
source

I had a similar error when inheriting from QRunnable, which, by the way, is not a QObject.
Cause

  1. Bad inheritance
+1
source

/ , QObject, QGraphicsObject,

class MyEllipseItem : public QGraphicsEllipseItem, public QObject
{
    Q_OBJECT

public:
    MyEllipseItem (const QRectF & outline) : QGraphicsEllipseItem(outline)
    {

    }
};

, QGraphicsObject .

. QGraphicsObject.

+1

QObject First, :

, " , QObject ", , , - "YourClass QObject" MOC.

. ! .

:

#include<QObject>
#include<QGraphicsEllipseItem> 
class myclass :  public QObject , public QGraphicsEllipseItem{
Q_OBJECT


// your code...

};

0