[Solved] Connect signals and slots each other in different threads
-
Hi Folks,
I have a multithreaded application where I need to connect the signals and slots between different object who live in different threads.
Basically I use the following scenario to create multithreading application:
@- create the two object
- connect their signals and slots
- create a QThread object
- move the appropirate object into another thread
@
BUT I need the solution to I am able to connect signals and slots to another object after the moving of the specific object into another thread. So the modified version of the code above:
@- create the two object
- create a QThread object
- move the appropirate object into another thread
- during the running of the application connect specific signals and slots
@
How can I do that?
Regards,
Norbert -
Hi,
There is no problem in connecting the way you describe the connection between signal/slots. Remember that the QThread object stays in the creator thread, not in a new thread. Only the object moved to the Qthread is altered.
Making connections later is possible!
What problem did you encounter?? -
Hi,
yes, I know that the object stay in the creator object's thread, but I would connect to the object that moved into the thread. Is it not a problem?
Regards,
Norbert -
Hi,
No it's not a problem, unless you explicitly specify the connection type (which you shouldn't unless you know what you are doing) It will be resolved at runtime so the correct behavior will be selected for you.
-
Also, QObject::connect() is thread-safe :) http://qt-project.org/doc/qt-5/qobject.html#connect