QSignalBlocker Class
Exception-safe wrapper around QObject::blockSignals(). More...
| Header: | #include <QSignalBlocker> |
| qmake: | QT += core |
| Since: | Qt 5.3 |
This class was introduced in Qt 5.3.
Note: All functions in this class are reentrant.
Detailed Description
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.