Results 1 to 2 of 2

Thread: Thread safety with signals and slots

  1. #1
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Thread safety with signals and slots

    I have a thread safety question. A list of objects, let's say QList<MyItem> items, are visually represented in a certain widget. Each object in this list has a signal/slot connection to a function in this widget. This function, let's call it processItemChange, is called when an item has changed and therefore its visual representation in the widget has to change too. Now, assume that each item operates on a separate thread.

    Is it possible that at some point processItemChange is being executed simultaneously for two separate objects? My personal guess is that since I'm using Qt::AutoConnection and the signal emission happens from a separate thread, a) slot execution is scheduled for when the receiver returns to his event loop and b) two simultaneously scheduled slot calls will be executed in a serial (not parallel) fashion.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Thread safety with signals and slots

    Where is the processItemChange() function defined? In the widget? If so, then no, they are synchronized, they won't be ran concurrently and you don't have to worry.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    blooglet (15th March 2012)

Similar Threads

  1. Thread safety
    By BalaQT in forum Qt Programming
    Replies: 6
    Last Post: 26th July 2011, 15:58
  2. Are signals and slots thread safe?
    By Cruz in forum Qt Programming
    Replies: 12
    Last Post: 21st April 2011, 14:57
  3. QWidget and thread safety
    By spraff in forum Qt Programming
    Replies: 3
    Last Post: 22nd January 2009, 01:11
  4. QPointer and thread safety
    By Nb2Qt in forum Qt Programming
    Replies: 1
    Last Post: 22nd August 2008, 09:22
  5. QFile and thread-safety
    By Raistlin in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2008, 15:42

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.