My problem is that when I’m setting values to QPointF, I get strange values like 1.32841e+09 when I check what they really are.
I’m not getting those values when I print it out on the sixth line in the while-loop.
void MainView::showAllGraphs(){
QMapIterator<QString, QRectF> i(graphRectangles);
QPointF topLeft;
QPointF bottomRight;
QRectF maxRect;
while (i.hasNext()) {
i.next();
qreal tlX = i.value().topLeft().x();
qreal tlY = i.value().topLeft().y();
qreal brX = i.value().bottomRight().x();
qreal brY = i.value().bottomRight().y();
QTextStream(stdout) << tlY << " " << brY << endl;
if(tlY < topLeft.y()){
topLeft.setY(tlY);
topLeft.setX(tlX);
}
if(brY > bottomRight.y()){
bottomRight.setY(brY);
bottomRight.setX(brX);
}
}
maxRect.setTopLeft(topLeft);
maxRect.setBottomRight(bottomRight);
QTextStream(stdout) << topLeft.y() << " x " << topLeft.y() << endl;
graphicsScene>setSceneRect(maxRect);
graphicsView->fitInView(maxRect);
matrixUpdated(graphicsView->matrix());
}
With the first print, I get values between -100 and 100 (which is valid). When I print out at the end I suddenly get a value like 2.45841e+09 or sometimes 0. I don’t want it to change to that.
So what is the reason for this change in value? I can’t figure out why it is set to a value like that.
topLeftis not initialized.You only assign a value to
topLeft(orbottomRight) if your conditions are met. So make sure to initialize your rectangle to sensible values which allow meaningful comparisons in your if statements.Furthermore,
topLeftis not changed as you assume. In the while loop, you print the elements of the map (tlandbr), not (the uninitialized)topLeftthat you print after the while-loop. That’s why you get different results.