我想从另一个类/线程(DownloadThread()
类)访问进度条(在Ui_MainWindow()
类中)setMaximum()
。在
我试图使DownloadThread()
类从Ui_MainWindow
继承:
DownloadThread(Ui_MainWindow)
。但当我尝试设置最大进度条值时:
Ui_MainWindow.progressBar.setMaximum(100)
我得到这个错误:
AttributeError: type object 'Ui_MainWindow' has no attribute 'progressBar'
我的代码:
^{pr2}$
线程类:
在主窗口中:
^{pr2}$也可以用信号发出字符串和数字。在
直接的问题是
Ui_MainWindow
是一个类,而不是该类的实例。您必须将您的“窗口”self
传递给DownloadThread
。但无论如何,这不是正确的解决办法。不能从另一个线程访问PyQt小部件。相反,使用与您已经做过的相同的技术来更新状态文本(FTP download with text label showing the current status of the download)。在对代码的其他更改:
global localfile
是一种不好的做法。请改用self.localfile
。在localfile.close()
,with
来处理。在ftp.quit()
应替换为with
。在DownloadThread
从Ui_MainWindow
继承。在相关问题 更多 >
编程相关推荐