In my code, I have a large number of checks for equality...
for example:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsLineItem* x = new QGraphicsLineItem(50, 50, -50, -50);
QGraphicsView view(new QGraphicsScene(-200, -150, 400, 300) );
view.scene()->addItem(x);
view.show();
bool sameLine = true;
QLineF line1 = x->line();
qreal _length = line1.length();
foreach(QGraphicsItem* item, view.scene()->selectedItems())
{
QGraphicsLineItem *item2 = dynamic_cast<QGraphicsLineItem*>(item);
if(item2->line().length() != _length )
sameLine = false;
}
qDebug("same line: %d", sameLine);
}
It seems to work... in debug. Then when tested in release, it fails ?
Assume a single selected item, so item1
and item2
are the same, so regardless of precision, the above lengths should be equal....
In debug, I have not been able to see this fail... yet in release, it always fails !
The functions above (length()
) return a qreal
The only work-arounds I see would be
- to implement my own check for equality, that limits the precision, or
- cast any qreal
values to float
.
But it is illogical (and a lot of work, I would have to check LOTS of potential places).
Can somebody please explain why this is happening and how best to go around this problem ?