no match for call to (QPoint)(double) (double)
I am having a problem compiling a program that draws a polygon on a QGraphicsScene.
The problem is the values supplied to QPoint. The error is 'no match for call to (QPoint)(double) (double)'.
I have changed the variable data type to float and even int! With the same error (NOT double, of course).
The hard coded values to the polygon line works.
I have attached the relevant code.
Any advice would be much appreciated.
[CODEvoid DataDisplay::drawData()
{
QPen outlinePen(Qt::black);
QPolygonF polygon;
double x,y;
QPoint p1,p2;
x = 10.4;
y = 20.5;
p1(10.4,20.5);
x = 120.2;
y = 30.2;
p2(x,y);
// polygon << QPointF((float)10.4, (float)20.5) << QPoint((float)120.2, (float)30.2);
polygon << p1 << p2;
outlinePen.setWidth(2);
QGraphicsScene *scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
QBrush greenBrush(Qt::green);
QBrush blueBrush(Qt::blue);
outlinePen.setWidth(2);
scene->addPolygon(polygon, outlinePen);
}][/CODE]
Re: no match for call to (QPoint)(double) (double)
you need use QPointF class instead of QPoint,
Re: no match for call to (QPoint)(double) (double)
Thank you
I tried that. It didn't work.
The following does:
Quote:
void DataDisplay::drawData()
{
QPen outlinePen(Qt::black);
QPolygonF polygon;
qreal x1,y1,x2,y2;
QPointF p1,p2;
x1 = 10.8;y1=20.1;
x2 = 120.2;y2=30.2;
p1.setX(x1);
p1.setY(y1);
p2.setX(x2);
p2.setY(y2);
// polygon << QPointF((float)10.4, (float)20.5) << QPoint((float)120.2, (float)30.2);
polygon << p1 << p2;
outlinePen.setWidth(2);
QGraphicsScene *scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
QBrush greenBrush(Qt::green);
QBrush blueBrush(Qt::blue);
outlinePen.setWidth(2);
scene->addPolygon(polygon, outlinePen);
}
Re: no match for call to (QPoint)(double) (double)
This is the line that causes the compilation error. The error message is telling you that the QPoint (and QPointF) class has no method with the signature:
Code:
void QPoint::operator()( double arg1,
double arg2
);
which is what your expression translates to. I think you are confusing this with a constructor. You could simply replace this line with this assignment (after changing p1 to QPointF):