Cruz
26th June 2014, 14:08
Hello!
I would like to add signal and slot capability to a QGraphicsEllipseItem. I read that I should inherit from QObject as well, but it didn't work. This code:
class ComState : public QGraphicsEllipseItem, QObject
{
Q_OBJECT
double comRadius;
public:
ComState(QGraphicsItem *parent = 0);
~ComState(){};
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
signals:
void stateChangedOut();
};
ComState::ComState(QGraphicsItem *parent)
: QGraphicsEllipseItem(parent),QObject()
{
comRadius = 0.05;
setFlags(QGraphicsItem::ItemIsMovable);
setRect(QRectF(-comRadius, -comRadius, 2.0*comRadius, 2.0*comRadius));
}
Produces this compile error:
debug\moc_ComState.cpp:44: error: 'staticMetaObject' is not a member of 'QGraphicsEllipseItem'
debug\moc_ComState.cpp: In member function 'virtual void* ComState::qt_metacast(const char*)':
debug\moc_ComState.cpp:64: error: 'qt_metacast' is not a member of 'QGraphicsEllipseItem'
debug\moc_ComState.cpp: In member function 'virtual int ComState::qt_metacall(QMetaObject::Call, int, void**)':
debug\moc_ComState.cpp:69: error: 'qt_metacall' is not a member of 'QGraphicsEllipseItem'
I would really like to make this work instead of going the QGraphicsObject way, because I'm using things that QGraphicsEllipseItem provides.
What do I do now?
Thanks
Cruz
I would like to add signal and slot capability to a QGraphicsEllipseItem. I read that I should inherit from QObject as well, but it didn't work. This code:
class ComState : public QGraphicsEllipseItem, QObject
{
Q_OBJECT
double comRadius;
public:
ComState(QGraphicsItem *parent = 0);
~ComState(){};
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
signals:
void stateChangedOut();
};
ComState::ComState(QGraphicsItem *parent)
: QGraphicsEllipseItem(parent),QObject()
{
comRadius = 0.05;
setFlags(QGraphicsItem::ItemIsMovable);
setRect(QRectF(-comRadius, -comRadius, 2.0*comRadius, 2.0*comRadius));
}
Produces this compile error:
debug\moc_ComState.cpp:44: error: 'staticMetaObject' is not a member of 'QGraphicsEllipseItem'
debug\moc_ComState.cpp: In member function 'virtual void* ComState::qt_metacast(const char*)':
debug\moc_ComState.cpp:64: error: 'qt_metacast' is not a member of 'QGraphicsEllipseItem'
debug\moc_ComState.cpp: In member function 'virtual int ComState::qt_metacall(QMetaObject::Call, int, void**)':
debug\moc_ComState.cpp:69: error: 'qt_metacall' is not a member of 'QGraphicsEllipseItem'
I would really like to make this work instead of going the QGraphicsObject way, because I'm using things that QGraphicsEllipseItem provides.
What do I do now?
Thanks
Cruz