- Qt 6.10
- Qt Core
- C++ Classes
- QEventLoopLocker
- Qt 6.10.2 Reference Documentation

# QEventLoopLocker Class

The QEventLoopLocker class provides a means to quit an event loop when it is no longer needed. More...

Header: | `#include <QEventLoopLocker>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`

- List of all members, including inherited members

## Public Functions

| QEventLoopLocker()
| QEventLoopLocker(QEventLoop *loop)
| QEventLoopLocker(QThread *thread)
`(since 6.7)` | QEventLoopLocker(QEventLoopLocker &&other)
| ~QEventLoopLocker()
`(since 6.7)` void | swap(QEventLoopLocker &other)
`(since 6.7)` QEventLoopLocker & | operator=(QEventLoopLocker &&other)

## Related Non-Members

`(since 6.7)` void | swap(QEventLoopLocker &lhs, QEventLoopLocker &rhs)

## Detailed Description

The QEventLoopLocker operates on particular objects - either a QCoreApplication instance, a QEventLoop instance or a QThread instance.

This makes it possible to, for example, run a batch of jobs with an event loop and exit that event loop after the last job is finished. That is accomplished by keeping a QEventLoopLocker with each job instance.

The variant which operates on QCoreApplication makes it possible to finish asynchronously running jobs after the last gui window has been closed. This can be useful for example for running a job which uploads data to a network.

See also QEventLoop and QCoreApplication.

## Member Function Documentation

### `[noexcept]` QEventLoopLocker::QEventLoopLocker()

Creates an event locker operating on the QCoreApplication.

The application will attempt to quit when there are no more QEventLoopLockers operating on it, as long as QCoreApplication::isQuitLockEnabled() is `true`.

Note that attempting a quit may not necessarily result in the application quitting, if there for example are open windows, or the QEvent::Quit event is ignored.

See also QCoreApplication::quit() and QCoreApplication::isQuitLockEnabled().

### `[explicit noexcept]` QEventLoopLocker::QEventLoopLocker(QEventLoop *loop)

Creates an event locker operating on the loop.

This particular QEventLoop will quit when there are no more QEventLoopLockers operating on it.

See also QEventLoop::quit().

### `[explicit noexcept]` QEventLoopLocker::QEventLoopLocker(QThread *thread)

Creates an event locker operating on the thread.

This particular QThread will quit when there are no more QEventLoopLockers operating on it.

See also QThread::quit().

### `[noexcept, since 6.7]` QEventLoopLocker::QEventLoopLocker(QEventLoopLocker &&other)

Move-constructs an event-loop locker from other. other will have a no-op destructor, while responsibility for preventing the QEventLoop/QThread/QCoreApplication from quitting is transferred to the new object.

This function was introduced in Qt 6.7.

### `[noexcept]` QEventLoopLocker::~QEventLoopLocker()

Destroys this event loop locker object

### `[noexcept, since 6.7]` void QEventLoopLocker::swap(QEventLoopLocker &other)

Swaps the object and the state of this QEventLoopLocker with other. This operation is very fast and never fails.

This function was introduced in Qt 6.7.

### `[noexcept, since 6.7]` QEventLoopLocker &QEventLoopLocker::operator=(QEventLoopLocker &&other)

Move-assigns this event-loop locker from other. other will have a no-op destructor, while responsibility for preventing the QEventLoop/QThread/QCoreApplication from quitting is transferred to this object.

This function was introduced in Qt 6.7.

## Related Non-Members

### `[noexcept, since 6.7]` void swap(QEventLoopLocker &lhs, QEventLoopLocker &rhs)

Swaps the object and the state of lhs with rhs. This operation is very fast and never fails.

This function was introduced in Qt 6.7.