<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QReadLocker Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></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="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QReadLocker Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></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> <h3>Methods</h3><ul><li><div class="fn" /><b><a href="qreadlocker.html#QReadLocker">__init__</a></b> (<i>self</i>, QReadWriteLock <i>areadWriteLock</i>)</li><li><div class="fn" />QReadWriteLock <b><a href="qreadlocker.html#readWriteLock">readWriteLock</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qreadlocker.html#relock">relock</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qreadlocker.html#unlock">unlock</a></b> (<i>self</i>)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />object <b><a href="qreadlocker.html#__enter__">__enter__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qreadlocker.html#__exit__">__exit__</a></b> (<i>self</i>, object <i>type</i>, object <i>value</i>, object <i>traceback</i>)</li></ul><a name="details" /><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 class="cpp"> <span class="type"><a href="qreadwritelock.html">QReadWriteLock</a></span> lock; <span class="type"><a href="qbytearray.html">QByteArray</a></span> readData() { <span class="type">QReadLocker</span> locker(<span class="operator">&</span>lock); <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="keyword">return</span> data; } </pre> <p>It is equivalent to the following code:</p> <pre class="cpp"> <span class="type"><a href="qreadwritelock.html">QReadWriteLock</a></span> lock; <span class="type"><a href="qbytearray.html">QByteArray</a></span> readData() { lock<span class="operator">.</span>lockForRead(); <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> lock<span class="operator">.</span>unlock(); <span class="keyword">return</span> data; } </pre> <p>The <a href="qmutexlocker.html">QMutexLocker</a> documentation shows examples where the use of a locker object greatly simplifies programming.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QReadLocker" />QReadLocker.__init__ (<i>self</i>, <a href="qreadwritelock.html">QReadWriteLock</a> <i>areadWriteLock</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><b>See also</b> <a href="qreadwritelock.html#lockForRead">QReadWriteLock.lockForRead</a>().</p> <h3 class="fn"><a name="readWriteLock" /><a href="qreadwritelock.html">QReadWriteLock</a> QReadLocker.readWriteLock (<i>self</i>)</h3><p>Returns a pointer to the read-write lock that was passed to the constructor.</p> <h3 class="fn"><a name="relock" />QReadLocker.relock (<i>self</i>)</h3><p>Relocks an unlocked lock.</p> <p><b>See also</b> <a href="qreadlocker.html#unlock">unlock</a>().</p> <h3 class="fn"><a name="unlock" />QReadLocker.unlock (<i>self</i>)</h3><p>Unlocks the lock associated with this locker.</p> <p><b>See also</b> <a href="qreadwritelock.html#unlock">QReadWriteLock.unlock</a>().</p> <h3 class="fn"><a name="__enter__" />object QReadLocker.__enter__ (<i>self</i>)</h3><h3 class="fn"><a name="__exit__" />QReadLocker.__exit__ (<i>self</i>, object <i>type</i>, object <i>value</i>, object <i>traceback</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>