[PyKDE] PyQt Qthreads
Krzysztof Lichota
krzysiek at lichota.net
Tue Oct 31 17:26:26 GMT 2006
Gregor Kling napisał(a):
> I can see that the printouts are as intended, but
> the presentation in the WidgetTable ist presented when
> the thread is complete instead of an iterative update.
>
>
> Anyone has an idea ?
As far as I understand your code, in GUI you are running in loop,
processing incoming pieces of data. This will not work, GUI updating is
event-driven, so you should process one piece of data at the time and
return control to GUI event processing loop to update GUI.
In my apps I solve this problem by sending data to widgets in
QCustomEvent. Something like that (note that this is for Qt3, not Qt4, I
don't know if it has been changed):
Background thread does:
class FrontendCustomEvent(qt.QCustomEvent):
def __init__(self, data, *args):
apply(qt.QCustomEvent.__init__, (self,) + args)
self.pythonData = data
def sendEvent(object, data):
import qt
event = FrontendCustomEvent(data, qt.QEvent.User + 100)
qt.QApplication.postEvent(object, event)
while True:
sendEvent(mainWidget, "some data")
In main widget I have:
class MyWidget(qt.QWidget):
def customEvent(self, event):
if event.type() == qt.QEvent.User + 100:
itemData = event.pythonData
qt.QListViewItem(self.listView, itemData)
BTW. In your code you have race condition - if background thread does
not send data fast enough, you would stop processing prematurely. You
should use some other way of detecting if this is end of results, for
example a flag saying that all results were sent.
HTH
Krzysztof Lichota
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20061031/955d08c8/signature.bin
More information about the PyQt
mailing list