Solved "not list it in Q_INTERFACES" Warning ?
-
What is the problem here and how can I fix it ?
If more code necessary, please let me know, thank you./Projects/Cella_02/mycellitem.h:18: Warning: Class MyCellItem implements the interface QGraphicsItem but does not list it in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!
#ifndef MYCELLITEM_H #define MYCELLITEM_H #include <QGraphicsItem> #include <QPainter> class MyCellItem : public QObject, public QGraphicsItem { Q_OBJECT public: MyCellItem(); ~MyCellItem(); QRectF boundingRect() const; void paint(QPainter* painter, const QStyleOptionGraphicsItem *, QWidget *); }; #endif // MYCELLITEM_H
-
OK, fixed it, but still do not understand, why this is necessary and what for.
class MyCellItem : public QObject, public QGraphicsItem { Q_OBJECT Q_INTERFACES(QGraphicsItem) public: ...
-
It's needed for multitude of things, one of which is to provide RTTI when such is disabled for the compiler. You should refer to the docs for a full explanation on the macro. Also you're better off deriving from
QGraphicsObject
instead of the way you're doing it now.Kind regards.
-
thanks for reply!
this way ?
class MyCellItem : public QGraphicsObject //, public QGraphicsItem { Q_OBJECT // Q_INTERFACES(QGraphicsItem) public:
ps. how to mark this thread as SOLVED ?
-