<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Solved] Q_PROPERTY and QReadWriteLock]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">My application is full of threads and I have some instability that I suspect is due to race conditions. So to solve this I am planning to use "QReadWriteLock":<a href="https://qt-project.org/doc/qt-4.8/qreadwritelock.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://qt-project.org/doc/qt-4.8/qreadwritelock.html</a> locks on the properties of my objects.</p>
<p dir="auto">Since the normal signature for a Q_PROPERTY is that the read function should be const, I can't just use the "QReadWriteLock::LockForRead()":<a href="https://qt-project.org/doc/qt-4.8/qreadwritelock.html#lockForRead" target="_blank" rel="noopener noreferrer nofollow ugc">https://qt-project.org/doc/qt-4.8/qreadwritelock.html#lockForRead</a> function in the read since it is not a const function (normal compiler error associated with this).</p>
<p dir="auto">What is the best or preferred solution around this problem?<br />
a.) Remove the const qualifier from all my read functions?<br />
b.) Keep the read functions const but use const_cast to remove the const'ness from the lock and lock it?<br />
c.) Other options I should consider?</p>
<p dir="auto">From what I understand is that b.) is risky because it can cause undefined behaviour??</p>
<p dir="auto">Any help will be appreciated.</p>
]]></description><link>https://forum.qt.io/topic/33331/solved-q_property-and-qreadwritelock</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 17:52:03 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/33331.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 21 Oct 2013 12:42:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved] Q_PROPERTY and QReadWriteLock on Mon, 21 Oct 2013 14:27:14 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="NicuPopescu" date="1382365098"]<br />
@<br />
mutable QReadWriteLock rwlocker;<br />
@<br />
[/quote]</p>
<p dir="auto">Works perfectly, thank you.</p>
]]></description><link>https://forum.qt.io/post/199915</link><guid isPermaLink="true">https://forum.qt.io/post/199915</guid><dc:creator><![CDATA[TheBadger]]></dc:creator><pubDate>Mon, 21 Oct 2013 14:27:14 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Q_PROPERTY and QReadWriteLock on Mon, 21 Oct 2013 14:18:18 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">may be "this":<a href="http://stackoverflow.com/questions/8325400/how-to-call-a-non-const-method-from-a-const-method" target="_blank" rel="noopener noreferrer nofollow ugc">http://stackoverflow.com/questions/8325400/how-to-call-a-non-const-method-from-a-const-method</a> helps you (read the last post)</p>
<p dir="auto">@mutable QReadWriteLock rwlocker;@</p>
]]></description><link>https://forum.qt.io/post/199914</link><guid isPermaLink="true">https://forum.qt.io/post/199914</guid><dc:creator><![CDATA[NicuPopescu]]></dc:creator><pubDate>Mon, 21 Oct 2013 14:18:18 GMT</pubDate></item></channel></rss>