[PyKDE] Starting QApplication from a python thread

Jeremy Sanders jeremy at jeremysanders.net
Sat Feb 5 22:16:35 GMT 2005


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

Thanks

Jeremy

-- 
Jeremy Sanders <jeremy at jeremysanders.net>
http://www.jeremysanders.net/                Cambridge, UK
Public Key Server PGP Key ID: E1AAE053




More information about the PyQt mailing list