6.0.0-rc4Source

QEventLoopLocker Class

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

Header#include <QEventLoopLocker>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

Detailed Description

A locker keeps count of the work that is still going on. When the last locker for a target is destroyed, the target quits. It lets code that is spread over several objects, such as a number of asynchronous jobs, end the program once the last one is done, without a central counter:

void Job::start()
{
    m_lock = std::make_unique<QEventLoopLocker>();
    // ...
}
void Job::finish() { m_lock.reset(); }   // the last job to finish quits the application

The locker created without arguments counts for the application and quits it with QCoreApplication::quit(), unless QCoreApplication::setQuitLockEnabled() turned that off. One created with a QEventLoop or QThread counts for that object, which then has quit() called; a target that was destroyed in the meantime is ignored.

See also QCoreApplication::setQuitLockEnabled() and QEventLoop::quit().

Differences from Qt

None.

Member Function Documentation

QEventLoopLocker::QEventLoopLocker()

Constructs a locker for the application.

[explicit] QEventLoopLocker::QEventLoopLocker(QEventLoop *loop)

This is an overloaded function.

Constructs a locker for loop, which quits when the last locker for it is destroyed.

[explicit] QEventLoopLocker::QEventLoopLocker(QThread *thread)

This is an overloaded function.

Constructs a locker for thread, which quits when the last locker for it is destroyed.

QEventLoopLocker::~QEventLoopLocker()

Destroys the locker. If it was the last one for its target, the target quits.