You are not logged in.

Dear visitor, welcome to If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.


Friday, May 18th 2012, 1:33pm

[SOLVED] Do I need to use QMutex in this scenario?

Hi there!

I have got a simple question. I have my class with QObject as a base class, which runs in a separate the QThread. It is purely event driven class, it does not run any processing continually. It has several slots and signals connected by QueuedConnection to signals/slots of similar class instances also with QObject as a base class, each running in its own QThread.

Every important slot of this QObject-like class uses member variables - they are shared between several slots. My question is, whether I need to use mutexes or not to synchronize access to these member variables.

From my point of view, I do not. I imagine the process like this: every connection with other QObjects' signals/slots is of QueuedConnection type and QThread event loop executes only one slot at a time. Therefore, if two slots, both changing same shared variables, are called at approximately same time, they are executed in the order they were put in the queue.

Am I right?


This post has been edited 2 times, last edit by "juchuchuu" (May 18th 2012, 7:48pm)


Friday, May 18th 2012, 6:47pm

Yes, you are right.

If everything is connected via queued connection, then slots can only be run in the thread that the object exists in => single threaded access.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.