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

Alan Ezust alan.ezust at gmail.com
Wed Jan 7 22:33:03 GMT 2015


You can start up your own QEventLoop in the other thread...


On Wed, Jan 7, 2015 at 1:27 PM,  <Mathias.Born at gmx.de> wrote:
> 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
>
>
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list