[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] How to get Qt signals delivered to a pure python thread.
From: Andreas Pakulat <apaku () gmx ! de>
Date: 2015-01-07 22:53:36
Message-ID: CAExHGmRRpvrpE+3cZd108O-0m9iOjKhG=72v=hHpoX=7uh9Eww () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hi,
On Wed, Jan 7, 2015 at 4:11 PM, Ilya Kulakov <kulakov.ilya@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
[Attachment #5 (text/html)]
<div dir="ltr">Hi,<div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan \
7, 2015 at 4:11 PM, Ilya Kulakov <span dir="ltr"><<a \
href="mailto:kulakov.ilya@gmail.com" \
target="_blank">kulakov.ilya@gmail.com</a>></span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">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.<br> 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.<br> <br>
Is there any utility classes in PyQt to subscribe to Qt events from non-Qt \
threads?<br></blockquote><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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).</div><div><br></div><div>Andreas</div></div></div></div>
[Attachment #6 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic