[PyQt] [python/Qt4]a problem of QThread

Hans-Peter Jansen hpj at urpla.net
Tue May 6 09:03:30 BST 2008


Am Dienstag, 6. Mai 2008 schrieb tsic:
> Hello,
> I tried to program a chat interface between a server and many clients.
> when I used Qthread this message apear when I execute my program file
> from DOS:

Has anybody ported PyQt to DOS without my knowledge? ;-)

> QThread: Destroyed while thread is still running
> And stop the execution of the program because pythonw.exe has find a
> problem and must close...
> this is my code
>
>     def conec(self):
>         HOST = self.adripes.text()
>         PORT = int(self.nipes.text())
>         thread = Thread(HOST, PORT)
>         QtCore.QObject.connect(thread, SIGNAL("finished()"),thread,
> SLOT("deleteLater()"))
>         thread.start()

...and the thread disappears, when this method finish. 

This is by far the most frequent PyQt beginners failure:

You either need to keep a reference on the thread object 
(e.g.: s/thread/self.thread/)
or add a parent object to the ctor, as most Qt objects do.
How to do the latter is left as an exercise to the implementor.

Pete


More information about the PyQt mailing list