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