[PyQt] How to get Qt signals delivered to a pure python thread.

Mathias.Born at gmx.de Mathias.Born at gmx.de
Wed Jan 7 21:27:02 GMT 2015


On 07.01.2015, 16:11:36 Ilya Kulakov wrote:
> I have a python thread that mainly serves a network connection. In
> this thread (due to the logic/architecture of my app) I need connect
> to a slot of QApplication clipboard.
> Something straightforward like connect does not work because my
> thread does not have a Qt event loop. However if I connect with a
> DirectConnect, I'll get my callback called, but sometimes it simply
> stops to work: no events are delivered.

> Is there any utility classes in PyQt to subscribe to Qt events from non-Qt threads?

I can't answer your last question, but I'd like to comment about the rest.

http://doc.qt.io/qt-5/qt.html#ConnectionType-enum
clearly describes "DirectConnect" as:

"The slot is invoked immediately when the signal is emitted.
The slot is executed in the signalling thread."

This means your callback is executed in the main thread. I suspect
it accesses objects of the other python thread without proper
synchronization. This may cause subtle multi-threading bugs, where
things "sometimes" happen.

Best Regards,
Mathias






More information about the PyQt mailing list