Prevent Firing Signals in Qt

Prevent Firing Signals in Qt

Asked on December 21, 2018 in Qt.
Add Comment


  • 3 Answer(s)

    By using the link clicked signal because as only yield  clicked the check box,  check it using setChecked:

    If the signal have  one specific time, use QObject::blockSignals:

    bool oldState = checkBox->blockSignals(true);
    checkBox->setChecked(true);
    checkBox->blockSignals(oldState);
    

    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.

    Answered on December 21, 2018.
    Add Comment

    The QObjects using QObject::blockSignals()remember the old state returned from the function call and refresh:

    class SignalBlocker
    {
    public:
       SignalBlocker( QObject *obj ) : m_obj( obj ), m_old( obj->blockSignals( true ) )
      {
      }
     
    ~SignalBlocker()
    {
        m_obj->blockSignals( m_old );
    }
     
    private:
       QObject *m_obj;
       bool m_old;
    };
    

    Modify:

    In  Qt 5.3 click  to get more information   QSignalBlocker

    Answered on December 21, 2018.
    Add Comment

    They initialize the process:

    In QObject::disconnect remove the corresponding signal-slot connection and can QObject::connect againts  the once.

    Answered on December 21, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.