PDA

View Full Version : Thread safety with signals and slots



blooglet
15th March 2012, 13:09
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.

wysota
15th March 2012, 15:03
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.