We have a QCheckBox object, when user checks it or removes check we want to call a function so we connect our function to stateChanged ( int state ) signal. On the other hand, according to some condition we also change the state of QCheckBox object inside code, and this causes the unwanted signal.
Is there any way to prevent firing signal under some conditions?
You can use the
clickedsignal because it is only emitted when the user actually clicked the check box, not when you manually check it usingsetChecked.If you just don’t want the signal to be emitted at one specific time, you can use
QObject::blockSignalslike this:The downside of this approach is that all signals will be blocked. But I guess that doesn’t really matter in case of a
QCheckBox.