Slider.setValue doen't send notification in specific case


Hi. I recently came across a very peculiar bug. I initialize four sliders in my constructor with sendNotification flag. The idea is that they will fire a listener. The listener will then set variables to the value of the slider. I noticed that only three variables are initialized. I then noticed that for the three of them I set value inside corresponding slider range and for the fourth one I set a value outside the range. Therefore:
sliderDeviance.setRange(100, 1000.0);
sliderDeviance.setValue(100, sendNotification);
won’t fire the listener. Nor
sliderDeviance.setRange(100.0, 1000.0);
sliderDeviance.setValue(100.0, sendNotification);
will do it. However this:
sliderDeviance.setRange(100.0, 1000.0);
sliderDeviance.setValue(100.1, sendNotification);
will do the job.
Is this an intended behaviour? Am I doing something wrong? It doesn’t seem very intuitive. There are probably some folks scratching their heads as to why their listeners doesn’t fire from the constructor. I think listener should be fired in all situations mentioned above. Or if not, JUCE should signal somehow why they don’t.


I’m not sure, but when you set the range, the slider might be initialised to the min value? If so, when you then set the value to the same value (as in the first 2 cases), the listener will not fire as they internally check that the value has changed.


Yep - that’s it. If the slider’s value isn’t changed a call to . setValue won’t call any listeners.


You are right. I fell a bit silly now.

However I still think it is not very intuitive to have sendNotification flag not firing a callback in such case. But it now makes sense.


There are a number of places where this could be clearer in the documentation, I’ll add it now.