Qt blockSignals


有时我们需要,控件不接收信号,可以使用 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.使用说明

例如:

QCboBox动态添加item的时候,它会发出xxxChanged信号,但是初始情况下我们不希望其发出,待初始化完成后再发出。

则可以:

先设置blockSignals(true);//阻塞信号

添加item;

设置blockSignals(false);//取消信号阻塞

example:

1 m_ControlsboBox>blockSignals(true); 2 m_ControlsboBox>addItems( AngleList()); 3 m_ControlsboBox>setCurrentIndex(0);//45度 4 m_ControlsboBox>blockSignals(false);



上一篇:Qt 安装完整版教程(Linux)

下一篇:MATLAB 2022b 图文安装保姆级教程|Matlab密匙|激活步骤|


Qt
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图