On 23-04-2019 20:15, Ron Tarrant wrote:

I hooked up some signals to a few SpinButtons (one with double increments, the other two with float) and I'm getting some double-firings on the two float buttons, but not all the time.

The buttons are as follows:

  • double,
  • float with no extra precision, and
  • float with precision down to 1000ths.

The results when they're hooked up to the onValueChanged signal:

  • the double never double-fires (how's that for irony?),
  • the float with no extra precision always double-fires, and
  • the 1000ths float only double-fires as it's crossing a boundary of 3/1000ths in either direction.

With the onOutput signal:

  • double always double-fires,
  • float with no extra precision always double-fires except for the first time it's clicked, and
  • 1000ths float always double-fires.

When I say "double-fires" I mean that it reports the value before and after the value changes, so something like:

click:

  • 0.1
  • 0.2

click:

  • 0.2
  • 0.3

click:

  • 0.3
  • 0.4

Here's the code:

...

There seem to be a precision/rounding error when using float, changing
the step variable in the two float spin button classes to double fixes
the issue.

A float can't exactly represent 0.1 with the precision of float that
is actually 0.100000001490116119384765625 witch seems to be the source
of the issue.