QEventLoopLocker Class
The QEventLoopLocker class provides a means to quit an event loop when it is no longer needed. More…
| Header | #include <QEventLoopLocker> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QEventLoopLocker() | |
| QEventLoopLocker(QEventLoop *loop) | |
| QEventLoopLocker(QThread *thread) | |
| ~QEventLoopLocker() |
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.
QEventLoopLocker::QEventLoopLocker(QEventLoop *loop)
This is an overloaded function.
Constructs a locker for loop, which quits when the last locker for it is destroyed.
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.