I have a threaded application where I do have a network thread. The UI-part passes a callback
to this thread. The thread is a normal python thread - it's NO QThread
.
Is it possible to emit PyQT Slot within this thread?
I have a threaded application where I do have a network thread. The UI-part passes a callback
to this thread. The thread is a normal python thread - it's NO QThread
.
Is it possible to emit PyQT Slot within this thread?
No, it is not possible to emit a PyQt signal from a python thread like this.
However, a possible solution is to use an additional object shared by both threads, making the necessary operations to finally emit a thread-safe PyQt signal.
Here is an implementation of a "SafeConnector" class, making use of a pair of connected sockets and a Queue to exchange data between the two threads, and using a QSocketNotifier to get back in Qt's loop. A QObject is used to make it possible to emit a proper Qt signal: