QReadLocker Class
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks for read access. More…
| Header | #include <QReadLocker> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QReadLocker(QReadWriteLock *l) | |
| ~QReadLocker() | |
| void | unlock() |
| void | relock() |
| QReadWriteLock * | readWriteLock() const |
Detailed Description
A QReadLocker locks a QReadWriteLock for reading when it is constructed and unlocks it when it is destroyed.
QReadWriteLock lock;
QString value()
{
QReadLocker locker(&lock);
return sharedValue;
}
See also QWriteLocker and QReadWriteLock.
Differences from Qt
The locker is neither movable nor copyable. The lock pointer must not be nullptr.
Member Function Documentation
QReadLocker::QReadLocker(QReadWriteLock *l)
Constructs a QReadLocker and locks l for reading. The lock is released when the locker is destroyed.
QReadLocker::~QReadLocker()
Destroys the locker and unlocks the lock if it is currently held by this locker.
QReadWriteLock * QReadLocker::readWriteLock() const
Returns the read-write lock this locker operates on.
void QReadLocker::relock()
Relocks the lock for reading after it was unlocked with unlock(). Does nothing if the lock is already held by this locker.
See also unlock().
void QReadLocker::unlock()
Unlocks the lock if this locker holds it.
See also relock().