Qt -- blockSignals函数的用法

该函数的原型:bool QObject::blockSignals(bool block)

官方解释: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.

理解:如果block为真,阻塞信号,或者如果block为假,取消信号阻塞。如果信号被阻塞,被发射的信号消失在超空间。

实际应用:

ui->deviceComboBox->blockSignals(true);//如果block为真,阻塞信号,或者如果block为假,取消信号阻塞。
        for(int i = 0; i < supportedDevice->getCount(); i++)
        {
            DeviceTreeNode const &node = supportedDevice->getItem(i);
            qDebug<<QString("%1,%2\n").arg(node.DeviceNumber).arg(node.Description);
            QString description = QString::fromWCharArray(node.Description);
            ui->deviceComboBox->addItem(description);
        }
        ui->deviceComboBox->blockSignals(false);//如果block为真,阻塞信号,或者如果block为假,取消信号阻塞。

 

posted @ 2024-01-05 09:37  手磨咖啡  阅读(274)  评论(0编辑  收藏  举报