[PyQt] QThread problem
Sergio Jovani
lesergi at gmail.com
Mon Dec 8 13:48:01 GMT 2008
El Monday 08 December 2008 03:53:28 vàreu escriure:
> On Mon, Dec 8, 2008 at 12:53 AM, Sergio Jovani <lesergi at gmail.com> wrote:
> > Hi all,
> >
> > I'm developing a downloads application and I have created a QThread for
> > that reason. I start the QThread with no problems, but when I try
> > terminate it clicking on cancel pushbutton, I can't, application freezes.
> > Thanks in advance. Here the code:
> >
> > ---
> >
> > class MainWindow(QMainWindow):
> > def __init__(self, parent = None):
> > QMainWindow.__init__(self, parent)
> > ...
> > self.pbCancel=QPushButton(self.tr("Cancel"))
> > self.connect(self.pbCancel, SIGNAL("clicked()"),
> > self.cancel) ...
> > def download(self):
> > ...
> > self.threadDownload = Download(url, path, filename)
> > self.threadDownload.start()
> >
> > def cancel(self):
> > self.threadDownload.terminate()
> > self.threadDownload.wait()
> >
> > class Download(QThread):
> > def __init__(self, url, path, filename, parent = None):
> > QThread.__init__(self, parent)
> > self.path=path
> > self.url=url
> > self.filename=filename
> >
> > def run(self):
> > os.chdir(self.path)
> >
> > urllib.urlretrieve(self.url,self.filename,reporthook=self.myreporthook)
> > _______________________________________________
> > PyQt mailing list PyQt at riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
> def download(self):
> ...
> self.threadDownload = Download(url, path, filename)
> self.threadDownload.start()
> qApp.processEvents()
Hi,
Thanks for reply, but this does not solve the problem. I've tried and it still
freeze when I want to terminate QThread.
-------------------------------------------------------
More information about the PyQt
mailing list