Can't get QMap value using a <double> key
-
I'm facing the problem that I can't get the value of a QMap using a key other than using a QMapIterator key.
I have such QMap:
QMap<double, QList<double> > dynamic_Data;
And as you can see I can't get value using
133040
as a key.QMapIterator<double, QList<double> > i(dynamic_Data); if (i.hasNext()) { i.next(); qDebug() << i.key() << ":" << i.value(); qDebug() << dynamic_Data.value(i.key()); qDebug() << dynamic_Data.value(double(133040)); }
Output:
133040 : (31.8689, 49.2064) (31.8689, 49.2064) ()
Maybe I don't know something about QMap or I'm doing something wrong?
-
I'm facing the problem that I can't get the value of a QMap using a key other than using a QMapIterator key.
I have such QMap:
QMap<double, QList<double> > dynamic_Data;
And as you can see I can't get value using
133040
as a key.QMapIterator<double, QList<double> > i(dynamic_Data); if (i.hasNext()) { i.next(); qDebug() << i.key() << ":" << i.value(); qDebug() << dynamic_Data.value(i.key()); qDebug() << dynamic_Data.value(double(133040)); }
Output:
133040 : (31.8689, 49.2064) (31.8689, 49.2064) ()
Maybe I don't know something about QMap or I'm doing something wrong?
-
I'm guessing that @JonB is correct.
You can also try:
qDebug() << Qt::fixed << qSetRealNumberPrecision(20) << i.key();
Cheers.
-
A Atr0p0s has marked this topic as solved on
-
I'm guessing that @JonB is correct.
You can also try:
qDebug() << Qt::fixed << qSetRealNumberPrecision(20) << i.key();
Cheers.
-
@Paul-Colby @JonB you are right, the key isn't exactly 133040. I guess it's better not to use double type for keys. Thank you, men.
@Atr0p0s said in Can't get QMap value using a <double> key:
I guess it's better not to use double type for keys
:) You have to be careful with
double
s. As a great author once said [paraphrased]: "All [well, some] doubles are equal, and some doubles are more equal than others" ;-)