Exception-safe wrapper around QObject::blockSignals(). More...
Header: | #include <QSignalBlocker> |
qmake: | QT += core |
Since: | Qt 5.3 |
Note: All functions in this class are reentrant.
QSignalBlocker(QObject *object) | |
QSignalBlocker(QObject &object) | |
QSignalBlocker(QSignalBlocker &&other) | |
~QSignalBlocker() | |
void | reblock() |
void | unblock() |
QSignalBlocker & | operator=(QSignalBlocker &&other) |
Exception-safe wrapper around QObject::blockSignals().
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 }
is thus equivalent to
const bool wasBlocked = someQObject->blockSignals(true); // no signals here someQObject->blockSignals(wasBlocked);
except the code using QSignalBlocker is safe in the face of exceptions.
See also QMutexLocker and QEventLoopLocker.
Constructor. Calls object->blockSignals(true).
This is an overloaded function.
Calls object.blockSignals(true).
Move-constructs a signal blocker from other. other will have a no-op destructor, while repsonsibility for restoring the QObject::signalsBlocked() state is transferred to the new object.
Destructor. Restores the 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.
Re-blocks signals after a previous unblock().
The numbers of reblock() and unblock() calls are not counted, so every reblock() undoes any number of unblock() calls.
Temporarily restores the QObject::signalsBlocked() state to what it was before this QSignaBlocker'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() calls.
Move-assigns this signal blocker from other. other will have a no-op destructor, while repsonsibility 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.
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: