[Solved] Q_PROPERTY and QReadWriteLock
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":https://qt-project.org/doc/qt-4.8/qreadwritelock.html locks on the properties of my objects.
Since the normal signature for a Q_PROPERTY is that the read function should be const, I can't just use the "QReadWriteLock::LockForRead()":https://qt-project.org/doc/qt-4.8/qreadwritelock.html#lockForRead function in the read since it is not a const function (normal compiler error associated with this).
What is the best or preferred solution around this problem?
a.) Remove the const qualifier from all my read functions?
b.) Keep the read functions const but use const_cast to remove the const'ness from the lock and lock it?
c.) Other options I should consider?
From what I understand is that b.) is risky because it can cause undefined behaviour??
Any help will be appreciated.
may be "this":http://stackoverflow.com/questions/8325400/how-to-call-a-non-const-method-from-a-const-method helps you (read the last post)
@mutable QReadWriteLock rwlocker;@
[quote author="NicuPopescu" date="1382365098"]
mutable QReadWriteLock rwlocker;
Works perfectly, thank you.