Qt C++ Error when drawing a simple polygon

262 Views Asked by At

I have an old c++ program that I need to bring back to life. My task now is to draw a single Polygon. I am stuck at the very beginning since I have no experience in graphics. The points I want to use to draw a Polygen are stored in

QVector < QPointF> points which looks like that:

enter image description here

Now I want to draw my Polygon. I use this code:

            ggScene = new QGraphicsScene();   
            QPolygonF shape(points);
            QGraphicsItem* gg = ggScene->addPolygon(shape);

When compiling I get the following error:

cannot convert QGraphicsPolygonItem* to QGraphiscItem in initialization

Can anybiody help me on this please, thank you.

1

There are 1 best solutions below

0
On

I'm going to go out on a limb and guess that the actual error message is...

cannot convert ‘QGraphicsPolygonItem*’ to ‘QGraphicsItem*’ in initialization

(Note QGraphicsItem* rather than just QGraphicsItem)

If that's the case then the problem is probably that the compiler is only seeing a forward declaration of QGraphicsPolygonItem. Hence it is not aware that QGraphicsPolygonItem inherits from QGraphicsItem and so cannot perform the implicit conversion from QGraphicsPolygonItem* to QGraphicsItem*.

The fix is probably the simple addition of...

#include <QGraphicsPolygonItem>