I have a QVariant
that stores a double value. One place the value is coming from is a QDoubleSpinBox
(but not only!), which has a min (0.3) and max (1.0) as limits.
I've noticed that I get an exception (the code is written like this) when I set the value below the minimum. What's surprising is that I'm actually setting the value to 0.3.
Through debugging I found out that the following code is the reason why this is happening:
// value is QVariant
auto valueDouble = value.toDouble();
// use valueDouble
What happens is that when I set the value to 0.3 internally
value = 0.3
valueDouble = 2.9999999999999999
And 2.9999... is definitely below 0.3 hence the reason why I get the exception. Of course the 0.3
is probably a display "error" by the debugger inside Qt Creator. Nevertheless I'm more concerned about the internal error.
I also tried using QVariant::toFloat()
and I got 0.300000012.
Needless to say this not only creates poor user experience but internally also leads to all sorts of issues.
I can make it so that the QDoubleSpinBox
doesn't allow such behaviour however as I've mentioned such values comes from different locations in the applications so this issue needs to be handled on a deeper level.