Solved Issues When Add the Q_OBJECT to My SubClass of QGraphicsRectItem
-
like the head file, i had the subclass of
QGraphicsRectItem
.#ifndef GRAPHICSRECTITEM_H #define GRAPHICSRECTITEM_H #include <QGraphicsRectItem> class GraphicsRectItem : public QGraphicsRectItem { public: explicit GraphicsRectItem(const QRect &rect,QGraphicsItem *parent = Q_NULLPTR); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); protected: /**...*/ private: /**...*/ private: /**...*/ }; #endif // GRAPHICSRECTITEM_H
Every thing was ok. Where was no
Q_OBJECT
But, i want to use the
signal and slot
. so, i add theQ_OBJECT
. like below.class GraphicsRectItem : public QGraphicsRectItem { Q_OBJECT public: explicit GraphicsRectItem(const QRect &rect,QGraphicsItem *parent = Q_NULLPTR); /**...*/
Then, Has the some issues.
- ...error: 'staticMetaObject' is not a member of 'QGraphicsRectItem'...
- ...&QGraphicsRectItem::staticMetaObject, qt_meta_stringdata_GraphicsRectItem.data,...
- ...error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected QScopedPointer<QObjectData> d_ptr;
- ...error: within this context return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
...
I just want to use the
signal and slot
. so Add theQ_OBJECT
in my class. But There has some wrong!I didn't understand
Q_OBJECT
well.Thank u.
-
@joeQ said in Issues When Add the Q_OBJECT to My SubClass:
Q_OBJECT
Hi, I would recomment you taking some time and reading throught the docu.
I'm not sure if QGraphicsRectItem actually subclasses of QObject but adding a
#include <QObject>
might help :) -
QGraphicsRectItem is not from QObject. You can't do this. Why do you want add Q_OBJECT ?
-
I add the
#include<QObject>
. it didn't work.In the doc waht you said. I searched the
QGraphicsRectItem
orQGraphicsItem
. and want to know that did them Inherited theQObject
.
They didn't inheritedQObject
. -
I want to use the signal and slot. I want to emit signal to scene(or to another rect item) when rect item size changed.
-
Then do something like this. It should work. Inherit from QObject.
class MyItem : public QObject,public QGraphicsRectItem
{
Q_OBJECT
public:
MyItem();
}; -
Yes, (0o0), it's ok! Thank u. Very much. Excellent.