有时我们需要,控件不接收信号,可以使用 blockSignals
当设置为true时,QObject对象[子类]不会发出信号
1、函数原型
1 bool QObject::blockSignals(bool block) 2 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). If block is false, no such blocking will occur. 3 The return value is the previous value of signalsBlocked(). 4 Note that the destroyed() signal will be emitted even if the signals for this object have been blocked. 5 Signals emitted while being blocked are not buffered. 6 See also signalsBlocked() and QSignalBlocker.
2.使用说明
例如:
QComboBox动态添加item的时候,它会发出xxxChanged信号,但是初始情况下我们不希望其发出,待初始化完成后再发出。
则可以:
先设置blockSignals(true);//阻塞信号
添加item;
设置blockSignals(false);//取消信号阻塞
example:
1 m_Controls.comboBox->blockSignals(true); 2 m_Controls.comboBox->addItems( AngleList()); 3 m_Controls.comboBox->setCurrentIndex(0);//45度 4 m_Controls.comboBox->blockSignals(false);
标签:blockSignals,false,Qt,comboBox,Controls,true,blocked From: https://www.cnblogs.com/ybqjymy/p/17846812.html