how to connect a signal to a slot in a different thread?
-
06-07-2019 - |
Question
Qt uses signals and slots normally in a single thread, so calling a signal will call a slot in the same thread signal called. Is it any way to use a signal-slot mechanism to pass a message to qt thread ( so slot will be called later in specified thread's context )?
Solution
Signals and slots across threads found on the start page of the official Qt documentation.
OTHER TIPS
I think the usual way of dealing with that is to have the signal handler enqueue some other function (using boost::bind or some such functor thing) and then have the target threadqueue run it later.
At least with Qt4 that is no problem at all.YOu just need to set up the connection somewhere that you have variables pointing to both of the threads. (i.e. usually in main())