threading, qt, and the freakout

Phil Thompson phil at riverbankcomputing.co.uk
Tue Nov 30 16:23:56 CET 2004


What versions of Python, PyQt, SIP, Qt?

Qt imposes restrictions on which parts of the API can be called in
different threads - check the Qt documentation.

Python has bugs in its thread implementation. These (the ones that affect
PyQt anyway) are fixed in Python 2.4.

Also see the "Support for Threads" section in the PyQt documentation.

Phil

> Hey everyone,
>
> Why doesn't this work? The code speaks much more clearly than I do,
> so i shortened it and pasted it below.  Running this
> and clicking on 'Break Me' will... freak out the window...
>
> But... only when the pushbutton_obj.setText("Updated") line
> is in the thread. If I comment out the threading code
> and uncomment the line below "#WORKS", the button text
> updates fine. But in the thread it breaks...
>
> I feel like I'm being stupid here, so ANY suggestions are
> much appreciated.
>
> Thanks all.
> Ben Floyd
> even at pondie.com
>
>
> #############CUT#############
> from qt import *
> import sys
> import threading
>
> class Form1(QMainWindow):
>     def __init__(self,parent = None,name = None,fl = 0):
>         QMainWindow.__init__(self,parent,name,fl)
>         self.setCentralWidget(QWidget(self,"qt_central_widget"))
>         self.pushButton1 = QPushButton(self.centralWidget(),"pushButton1")
>         self.pushButton1.setText("Break Me")
>         self.connect(self.pushButton1,SIGNAL("clicked()"),self.doSomething)
>
>     def doSomething(self):
>         a = DoStuff()
>         a.go(self.pushButton1)
>
> class DoStuff:
>     def go(self, pushbutton_obj):
>         def runThread():
>             #DOESNT WORK
>             pushbutton_obj.setText("Updated")
>
>         go = threading.Thread(target=runThread)
>         go.start()
>
>         #WORKS
>         #pushbutton_obj.setText("Updated")
>
> if __name__ == "__main__":
>     app = QApplication(sys.argv)
>     f = Form1()
>     f.show()
>     app.setMainWidget(f)
>     app.exec_loop()
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>





More information about the Python-list mailing list