<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- qreadwritelock.cpp --> <head> <title>Qt 4.6: QReadLocker Class Reference</title> <link href="classic.css" rel="stylesheet" type="text/css" /> </head> <body> <a name="//apple_ref/cpp/cl//QReadLocker"></a> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td> <td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="functions.html"><font color="#004faf">All Functions</font></a> · <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QReadLocker Class Reference<br /><span class="small-subtitle">[<a href="qtcore.html">QtCore</a> module]</span> </h1> <p>The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks for read access. <a href="#details">More...</a></p> <pre> #include <QReadLocker></pre><p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#thread-safe">thread-safe</a>.</p> <ul> <li><a href="qreadlocker-members.html">List of all members, including inherited members</a></li> </ul> <hr /> <a name="public-functions"></a> <h2>Public Functions</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qreadlocker.html#QReadLocker">QReadLocker</a></b> ( QReadWriteLock * <i>lock</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qreadlocker.html#dtor.QReadLocker">~QReadLocker</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QReadWriteLock * </td><td class="memItemRight" valign="bottom"><b><a href="qreadlocker.html#readWriteLock">readWriteLock</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qreadlocker.html#relock">relock</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qreadlocker.html#unlock">unlock</a></b> ()</td></tr> </table> <a name="details"></a> <hr /> <h2>Detailed Description</h2> <p>The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks for read access.</p> <p>The purpose of QReadLocker (and <a href="qwritelocker.html">QWriteLocker</a>) is to simplify <a href="qreadwritelock.html">QReadWriteLock</a> locking and unlocking. Locking and unlocking statements or in exception handling code is error-prone and difficult to debug. QReadLocker can be used in such situations to ensure that the state of the lock is always well-defined.</p> <p>Here's an example that uses QReadLocker to lock and unlock a read-write lock for reading:</p> <pre> QReadWriteLock lock; QByteArray readData() { QReadLocker locker(&lock); ... return data; }</pre> <p>It is equivalent to the following code:</p> <pre> QReadWriteLock lock; QByteArray readData() { lock.lockForRead(); ... lock.unlock(); return data; }</pre> <p>The <a href="qmutexlocker.html">QMutexLocker</a> documentation shows examples where the use of a locker object greatly simplifies programming.</p> <p>See also <a href="qwritelocker.html">QWriteLocker</a> and <a href="qreadwritelock.html">QReadWriteLock</a>.</p> <hr /> <h2>Member Function Documentation</h2> <a name="//apple_ref/cpp/instm/QReadLocker/QReadLocker"></a> <h3 class="fn"><a name="QReadLocker"></a>QReadLocker::QReadLocker ( <a href="qreadwritelock.html">QReadWriteLock</a> * <i>lock</i> )</h3> <p>Constructs a <a href="qreadlocker.html">QReadLocker</a> and locks <i>lock</i> for reading. The lock will be unlocked when the <a href="qreadlocker.html">QReadLocker</a> is destroyed. If <tt>lock</tt> is zero, <a href="qreadlocker.html">QReadLocker</a> does nothing.</p> <p>See also <a href="qreadwritelock.html#lockForRead">QReadWriteLock::lockForRead</a>().</p> <a name="//apple_ref/cpp/instm/QReadLocker/~QReadLocker"></a> <h3 class="fn"><a name="dtor.QReadLocker"></a>QReadLocker::~QReadLocker ()</h3> <p>Destroys the <a href="qreadlocker.html">QReadLocker</a> and unlocks the lock that was passed to the constructor.</p> <p>See also <a href="qreadwritelock.html#unlock">QReadWriteLock::unlock</a>().</p> <a name="//apple_ref/cpp/instm/QReadLocker/readWriteLock"></a> <h3 class="fn"><a name="readWriteLock"></a><a href="qreadwritelock.html">QReadWriteLock</a> * QReadLocker::readWriteLock () const</h3> <p>Returns a pointer to the read-write lock that was passed to the constructor.</p> <a name="//apple_ref/cpp/instm/QReadLocker/relock"></a> <h3 class="fn"><a name="relock"></a>void QReadLocker::relock ()</h3> <p>Relocks an unlocked lock.</p> <p>See also <a href="qreadlocker.html#unlock">unlock</a>().</p> <a name="//apple_ref/cpp/instm/QReadLocker/unlock"></a> <h3 class="fn"><a name="unlock"></a>void QReadLocker::unlock ()</h3> <p>Unlocks the lock associated with this locker.</p> <p>See also <a href="qreadwritelock.html#unlock">QReadWriteLock::unlock</a>().</p> <p /><address><hr /><div align="center"> <table width="100%" cellspacing="0" border="0"><tr class="address"> <td width="40%" align="left">Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies)</td> <td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td> <td width="40%" align="right"><div align="right">Qt 4.6.3</div></td> </tr></table></div></address></body> </html>