Qt - invalid conversion to child class
- by David Davidson
I'm drawing polygons using the Graphics View framework. I added a polygon to the scene with this:
QGraphicsPolygonItem *poly = scene->addPolygon(QPolygonF(vector_of_QPointF));
poly->setPos(some_point);
But I need to implement some custom behaviour like selection, mouse over indicator, and other similar stuff on the graphics item. So I declared a class that inherits QGraphicsPolygonItem:
#include <QGraphicsPolygonItem>
class GridHex : public QGraphicsPolygonItem
{
public:
GridHex(QGraphicsItem* parent = 0);
};
GridHex::GridHex(QGraphicsItem* parent) : QGraphicsPolygonItem(parent)
{
}
Not doing much with that class so far, as you can see. But shouldn't replacing QGraphicsPolygonItem with my GridHex class? This is throwing a " invalid conversion from 'QGraphicsPolygonItem*' to 'GridHex*' " error:
GridHex* poly = scene->addPolygon(QPolygonF(vector_of_QPointF));
What am I doing wrong?