[PyQt] QThread::run does not worl as expected
Phil Thompson
phil at riverbankcomputing.com
Tue Jun 29 17:28:10 BST 2010
On Thu, 17 Jun 2010 14:42:46 +0200, David Mugnai <dvd at develer.com> wrote:
> Hi phil,
>
> according to the docs, the QThread::run method should call exec (and
> thus start a new event loop), but this code doesn't work (it never ends)
>
>
>> #!/usr/bin/env python
>> #-*- coding: utf-8 -*-
>>
>> from PyQt4.Qt import *
>>
>> app = QApplication([])
>>
>> class Start(QEvent):
>> def __init__(self):
>> QEvent.__init__(self, QEvent.User)
>>
>> class Receiver(QObject):
>> def doSomething(self):
>> print 'doSomething'
>> qApp.quit()
>>
>> class Main(QObject):
>> def test(self):
>> r = self._r = Receiver()
>> t = self._t = QThread()
>> r.moveToThread(t)
>> QObject.connect(self, SIGNAL('test'), r.doSomething)
>> t.start()
>> self.emit(SIGNAL('test'))
>>
>> main = Main()
>> main.test()
>> app.exec_()
>
> If, intead of a QThread, I use a class like this:
>
>> class MyThread(QThread):
>> def run(self):
>> return self.exec_()
>
>
> all works as expected.
Should be fixed with tonight's SIP snapshot.
Thanks,
Phil
More information about the PyQt
mailing list