[PyQt] How to get Qt signals delivered to a pure python thread.
Andreas Pakulat
apaku at gmx.de
Wed Jan 7 22:53:36 GMT 2015
Hi,
On Wed, Jan 7, 2015 at 4:11 PM, Ilya Kulakov <kulakov.ilya at gmail.com> 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?
>
Delivery of signals to an objects slot when the object lives in another
thread requires a Qt event loop running in that thread, you won't get
around that if you really need a cross-thread signal/slot connection.
However an alternative is to keep the slot in the main thread and use
standard inter-thread communication (Lock/Condition or Queue from python)
to signal whatever you need to communicate to the thread.
Qt and PyQt offer some threading API as well (QThread, QMutex, QSemaphore,
QFuture) but I think you'd have to use QThread for those to work correctly
for your thread (and it sounds like that is also a significant change in
your design).
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150107/43bbdac9/attachment.html>
More information about the PyQt
mailing list