[PyQt] Threads with PyQt. Qt's or Python's?
Frédéric
frederic.mantegazza at gbiloba.org
Tue Feb 3 11:24:45 GMT 2009
Le 3/2/2009, "Giovanni Bajo" <rasky at develer.com> a écrit:
>> The documentation says that a QPainter can only paint on QImage, QPrinter
>> and QPicture, but not on QWidget and QPixmap (it seems that painting on
>> QGraphicsItem works fine, as I don't have warnings; can you confirm?).
>
>I'm unsure but yes, it probably works because it's a simply a QImage
>under the hoods.
Ok.
>Read the documentation about connecting signals and slots across threads
>(asynchronous thread connection). What you want is to simply emit a
>signal from the thread (self.emit(SIGNAL("UPDATED_PROGRESS"), value)),
>and connect to that signal from the main thread; in the slot, update the
>widget.
>
>The trick is that a signal/slot connection across a thread is different
>from a normal one: in a normal connection, slots are called immediately,
>within the "emit()" call. Instead, in an asynchronous connection, when
>the signal is emitted, an event is posted to the main thread (posting
>events is thread-safe); then the receiving thread's exec loop will
>process the event and call the correct slot.
Ok, I got it! I'll try to implement this...
Thanks again for your help :o)
PS: does it already exist a simple solution to adapt this code:
thread = threading.Thread(target=func)
thread.start()
using QThread?
--
Frédéric
More information about the PyQt
mailing list