[PyKDE] Threading QApplications. Possible?

Trost Johnson jfj at freemail.gr
Tue Sep 21 22:58:59 BST 2004


Gordon Tyler wrote:

>
> A couple of things to note here:
>
> 1. The Python "threading" module is higher-level and easier to use 
> than the lower-level "thread" module.
>
> 2. I don't think Python and Qt threading mix well, so you should use 
> QThread and related classes rather than Python threading.

Python session:

 >>> import threading
 >>> import qt
 >>> def startup_QT():
...    class qtaway (threading.Thread):
...        def __init__ (self):
...            threading.Thread.__init__ (self)
...            self.ready = threading.Condition ()
...            self.globs = globals ()
...            self.locs = locals ()
...            self._kill = 0
...        def run (self):
...            a = qt.QApplication ([])
...            hello = qt.QPushButton("Hello world!", None)
...            hello.resize(100, 30)
...            a.setMainWidget(hello)
...            hello.show()
...            a.enter_loop()
...    thr = qtaway ()
...    thr.start ()

 >>> startup_QT()

[ ... here the python console freezes until I exit the QApp .. ]


Any hints? Besides using QThread. I want to fall back to a simplistic 
Tkinter
gui if QT is not installed and I have to use python's threads.






More information about the PyQt mailing list