QSignalBlocker 类

异常安全包裹器围绕 QObject::blockSignals (). 更多...

头: #include <QSignalBlocker>
CMake: find_package(Qt6 COMPONENTS Core REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Since: Qt 5.3

注意: 此类的所有函数 可重入 .

公共函数

  QSignalBlocker (QSignalBlocker && other )
  QSignalBlocker (QObject & object )
  QSignalBlocker (QObject * object )
QSignalBlocker & operator= (QSignalBlocker && other )
  ~QSignalBlocker ()
void reblock ()
void unblock ()

详细描述

QSignalBlocker can be used wherever you would otherwise use a pair of calls to blockSignals(). It blocks signals in its constructor and in the destructor it resets the state to what it was before the constructor ran.

{
const QSignalBlocker blocker(someQObject);
// no signals here
}
					

因此相当于

const bool wasBlocked = someQObject->blockSignals(true);
// no signals here
someQObject->blockSignals(wasBlocked);
					

except the code using QSignalBlocker is safe in the face of exceptions.

另请参阅 QMutexLocker and QEventLoopLocker .

成员函数文档编制

QSignalBlocker:: QSignalBlocker ( QSignalBlocker && other )

移动构造信号阻塞器自 other . other will have a no-op destructor, while responsibility for restoring the QObject::signalsBlocked () state is transferred to the new object.

QSignalBlocker:: QSignalBlocker ( QObject & object )

这是重载函数。

调用 object .blockSignals(true).

QSignalBlocker:: QSignalBlocker ( QObject * object )

构造函数。调用 object ->blockSignals(true).

QSignalBlocker &QSignalBlocker:: operator= ( QSignalBlocker && other )

Move-assigns this signal blocker from other . other will have a no-op destructor, while responsibility for restoring the QObject::signalsBlocked () state is transferred to this object.

The object's signals this signal blocker was blocking prior to being moved to, if any, are unblocked except in the case where both instances block the same object's signals and *this is unblocked while other is not, at the time of the move.

QSignalBlocker:: ~QSignalBlocker ()

析构函数。还原 QObject::signalsBlocked () state to what it was before the constructor ran, unless unblock () has been called without a following reblock (), in which case it does nothing.

void QSignalBlocker:: reblock ()

重新阻塞之后信号,基于先前 unblock ().

The numbers of reblock() and unblock () calls are not counted, so every reblock() undoes any number of unblock () 调用。

void QSignalBlocker:: unblock ()

Temporarily restores the QObject::signalsBlocked () state to what it was before this QSignalBlocker 's constructor ran. To undo, use reblock ().

The numbers of reblock () and unblock() calls are not counted, so every unblock() undoes any number of reblock () 调用。