Is emitting signals inside QRunnable::run()
a right thing to do? I need to inform my GUI thread that image processed by QRunnable
is done. I am using QThreadPool
/QRunnable
because I need to be able to add new tasks to the pool while there are tasks in it already. I find it kind of hard to do that with QtConcurrent
and QFutureWatcher
.
The QRunnable
is using a QObject
created in run()
to connect to the target QObject
and emit signals.
If emitting from QRunnable
is not a good thing, is it possible to post events from there?
Yes, emitting signals and posting events are fine things to do in a QRunnable::run()
because they are both thread-safe. For the signals and events to be handled properly, the QObjects must have the correct thread affinity. See Threads and QObjects for more details.