Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QSignalBlocker Class Reference

Exception-safe wrapper around QObject::blockSignals(). More...

#include <qobject.h>

+ Collaboration diagram for QSignalBlocker:

Public Member Functions

Q_NODISCARD_CTOR QSignalBlocker (QObject *o) noexcept
 Constructor.
 
Q_NODISCARD_CTOR QSignalBlocker (QObject &o) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Calls {object}.blockSignals(true).
 
 ~QSignalBlocker ()
 Destructor.
 
Q_NODISCARD_CTOR QSignalBlocker (QSignalBlocker &&other) noexcept
 Move-constructs a signal blocker from other.
 
QSignalBlockeroperator= (QSignalBlocker &&other) noexcept
 Move-assigns this signal blocker from other.
 
void reblock () noexcept
 Re-blocks signals after a previous unblock().
 
void unblock () noexcept
 Temporarily restores the QObject::signalsBlocked() state to what it was before this QSignalBlocker's constructor ran.
 
void dismiss () noexcept
 

Detailed Description

Exception-safe wrapper around QObject::blockSignals().

Since
5.3

\inmodule QtCore

\reentrant

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, QEventLoopLocker

Definition at line 482 of file qobject.h.

Constructor & Destructor Documentation

◆ QSignalBlocker() [1/3]

QSignalBlocker::QSignalBlocker ( QObject * object)
inlineexplicitnoexcept

Constructor.

Calls {object}->blockSignals(true).

Definition at line 506 of file qobject.h.

◆ QSignalBlocker() [2/3]

QSignalBlocker::QSignalBlocker ( QObject & o)
inlineexplicitnoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Calls {object}.blockSignals(true).

Definition at line 512 of file qobject.h.

◆ ~QSignalBlocker()

QSignalBlocker::~QSignalBlocker ( )
inline

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.

Definition at line 542 of file qobject.h.

References QObject::blockSignals().

+ Here is the call graph for this function:

◆ QSignalBlocker() [3/3]

QSignalBlocker::QSignalBlocker ( QSignalBlocker && other)
inlinenoexcept

Move-constructs a signal blocker from other.

other will have a no-op destructor, while responsibility for restoring the QObject::signalsBlocked() state is transferred to the new object.

Definition at line 518 of file qobject.h.

References other().

+ Here is the call graph for this function:

Member Function Documentation

◆ dismiss()

void QSignalBlocker::dismiss ( )
inlinenoexcept
Since
6.7 Dismisses the QSignalBlocker. It will no longer access the QObject passed to its constructor. unblock(), reblock(), as well as ~QSignalBlocker() will have no effect.

Definition at line 562 of file qobject.h.

◆ operator=()

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

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.

Definition at line 526 of file qobject.h.

References other().

+ Here is the call graph for this function:

◆ reblock()

void QSignalBlocker::reblock ( )
inlinenoexcept

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.

Definition at line 548 of file qobject.h.

References QObject::blockSignals().

+ Here is the call graph for this function:

◆ unblock()

void QSignalBlocker::unblock ( )
inlinenoexcept

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() calls.

Definition at line 555 of file qobject.h.

References QObject::blockSignals().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: