異常安全包裹器圍繞 QObject::blockSignals (). 更多...
| 頭: |
#include <QSignalBlocker>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
|
| qmake: |
QT += core
|
注意: 此類的所有函數 可重入 .
| QSignalBlocker (QObject * object ) | |
| QSignalBlocker (QObject & object ) | |
| QSignalBlocker (QSignalBlocker && other ) | |
| ~QSignalBlocker () | |
(從 6.7 起)
void
|
dismiss () |
| void | reblock () |
| void | unblock () |
| QSignalBlocker & | operator= (QSignalBlocker && other ) |
QSignalBlocker can be used wherever you would otherwise use a pair of calls to QObject::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 .
[explicit noexcept]
QSignalBlocker::
QSignalBlocker
(
QObject
*
object
)
構造函數。調用 object ->blockSignals(true).
[explicit noexcept]
QSignalBlocker::
QSignalBlocker
(
QObject
&
object
)
調用 object .blockSignals(true).
這是重載函數。
[noexcept]
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.
[noexcept]
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.
[noexcept, since 6.7]
void
QSignalBlocker::
dismiss
()
Dismisses the QSignalBlocker . It will no longer access the QObject passed to its constructor. unblock (), reblock (), as well as ~ QSignalBlocker () 沒有起作用。
該函數在 Qt 6.7 引入。
[noexcept]
void
QSignalBlocker::
reblock
()
重新阻塞之後信號,基於先前 unblock ().
The numbers of reblock() and unblock () calls are not counted, so every reblock() undoes any number of unblock () 調用。
[noexcept]
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 () 調用。
[noexcept]
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.