[PyKDE] Starting QApplication from a python thread

Phil Thompson phil at riverbankcomputing.co.uk
Sun Feb 6 10:52:10 GMT 2005


On Saturday 05 February 2005 10:16 pm, Jeremy Sanders wrote:
> On a related not to my last posting, why doesn't the following code work?
>
> -----
> #!/usr/bin/env python
>
> import thread
> import sys
> import time
>
> def threadfn():
>      import qt
>      app = qt.QApplication([sys.argv[0]])
>      win = qt.QMainWindow()
>      win.setCaption('foo bar')
>      win.show()
>      app.exec_loop()
>
> t = thread.start_new_thread(threadfn, ())
>
> i = 0
> while 1:
>      print i
>      time.sleep(1)
>      i += 1
>
> ----
>
> After carefully reading the PyQt docs, it suggests that as long as I keep
> all pyqt references to a single thread, things should work.
>
> However the window never appears here, and the infinite loops stops
> counting.
>
> Am I missing something obvious.
>
> This is with PyQt-3.13 and python-2.3.4

It might work with Python 2.4 (or 2.3.5). Earlier versions of Python have 
threading bugs.

Phil




More information about the PyQt mailing list