Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Q_PROPERTY and QReadWriteLock
Qt 6.11 is out! See what's new in the release blog

[Solved] Q_PROPERTY and QReadWriteLock

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • TheBadgerT Offline
    TheBadgerT Offline
    TheBadger
    wrote on last edited by
    #1

    Hi,

    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.


    Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NicuPopescu
      wrote on last edited by
      #2

      Hi,

      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;@

      1 Reply Last reply
      0
      • TheBadgerT Offline
        TheBadgerT Offline
        TheBadger
        wrote on last edited by
        #3

        [quote author="NicuPopescu" date="1382365098"]
        @
        mutable QReadWriteLock rwlocker;
        @
        [/quote]

        Works perfectly, thank you.


        Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved