Results 1 to 2 of 2

Thread: Make a QSharedPointer like class thread-safe with signal/slots

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Aug 2011
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Make a QSharedPointer like class thread-safe with signal/slots

    If I understand your problem you want your pointer to act like a decorator for your instance of QObject. No matter what's called on the object you want the code to go through the operator overloading of the pointer first to synchronize the call and then delegate the execution to the object.

    Let me be honest, there's no such a thing in C++ (I'm talking about decorators).

    But it doesn't mean it's not possible with Qt. The problem is that you connect the signal to your object, so the compiler has no idea about the SynchronizedPointer that's taking care of it.
    What should be done is connecting the signal to the SynchronizedPointer instead, then delegate the execution to the encapsulated object's slot when the pointer receives the signal. You probably need to look deeper into Qt's meta objects and reflection documentation to come out with a generic solution but if that's not possible then you would need to write one pointer class for each type you want to decorate (not very exciting).

    PS : If the sexy solution works try writing a generic Decorator class, that would be awesome.
    Last edited by soft0613; 10th August 2011 at 16:50.

Similar Threads

  1. Are signals and slots thread safe?
    By Cruz in forum Qt Programming
    Replies: 12
    Last Post: 21st April 2011, 14:57
  2. Replies: 0
    Last Post: 22nd February 2011, 07:55
  3. thread-safe
    By babymonsta in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2010, 10:18
  4. Replies: 3
    Last Post: 19th January 2010, 20:26
  5. creating treeWidgetItem using emitted signal from thread class
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 08:37

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.