图片:
报错信息如下:
<dir style="color:red"> QObject::setParent: Cannot set parent, new parent is in a different threadQWidget::repaint: Recursive repaint detected
QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
</dir>
调用时代码如下:
class RunThread(QThread):
sig=pyqtSignal(str)
def __init__(self):
super(RunThread,self).__init__()
def __del__(self):
self.wait()
def run(self):
main.dlButton.update()
logging.info('Download Button:clicked.')
try:
main.pbar.setValue(0)
main.url=str(main.URL_lineEdit.text())
main.filename=str(main.Filename_lineEdit.text())
main.filepath=str(main.Path_lineEdit.text())
if not os.path.exists(main.filepath):
os.makedirs(main.filepath)
head=requests.head(main.url,headers=main.headers)
content=head.content
main.filesize=int(head.headers.get('Content-Length'))
#https://issuecdn.baidupcs.com/issue/netdisk/yunguanjia/BaiduNetdisk_7.2.8.9.exe|self.filepath+self.filename
response=requests.get(main.url,headers=main.headers,stream=True)
read=0
file_k_size=1024*2
with open(main.filepath+'/'+main.filename,'wb') as write_file:
for chunk in response.iter_content(chunk_size=file_k_size):
read+=file_k_size
read=min(read,main.filesize)
write_file.write(chunk)
main.pbar.setValue(int((read/main.filesize)*100))
main.pbar.update()
main.pbar.setValue(0)
main.statusBar_.showMessage('下载完成')
except Exception as exception:
logging.exception(exception)
subprocess.Popen('BugReport.pyw',shell=True)
运行时没有问题,但是偶尔有一两次未响应。
我的程序有logging记录的功能,但是貌似没什么用,没有记录到这个错误。
日志如下:
[2022-04-02 17:38:20,617] - [Downloader.pyw] - [11232] -[line:63] - [LEVEL:INFO] , In root: Icon loaded.
[2022-04-02 17:38:20,674] - [Downloader.pyw] - [11232] -[line:112] - [LEVEL:INFO] , In root: Ready.
[2022-04-02 17:38:20,884] - [Downloader.pyw] - [11232] -[line:179] - [LEVEL:DEBUG] , In root: Temp file deleted.
[2022-04-02 17:38:35,642] - [Downloader.pyw] - [11232] -[line:121] - [LEVEL:INFO] , In root: FileDialog Button:clicked.
[2022-04-02 17:38:38,804] - [Downloader.pyw] - [11232] -[line:148] - [LEVEL:INFO] , In root: Download Button:clicked. [2022-04-02 17:38:38,812] - [connectionpool.py] - [11232] -[line:1001] - [LEVEL:DEBUG] , In urllib3.connectionpool: Starting new HTTPS connection (1): issuecdn.baidupcs.com:443
[2022-04-02 17:38:40,948] - [connectionpool.py] - [11232] -[line:456] - [LEVEL:DEBUG] , In urllib3.connectionpool: https://issuecdn.baidupcs.com:443 "HEAD /issue/netdisk/yunguanjia/BaiduNetdisk_7.2.8.9.exe HTTP/1.1" 200 0
[2022-04-02 17:38:40,951] - [connectionpool.py] - [11232] -[line:1001] - [LEVEL:DEBUG] , In urllib3.connectionpool: Starting new HTTPS connection (1): issuecdn.baidupcs.com:443
[2022-04-02 17:38:41,061] - [connectionpool.py] - [11232] -[line:456] - [LEVEL:DEBUG] , In urllib3.connectionpool: https://issuecdn.baidupcs.com:443 "GET /issue/netdisk/yunguanjia/BaiduNetdisk_7.2.8.9.exe HTTP/1.1" 200 67765560
</dir>
我认为是在另一个类里调用了进度条的update()方法,我把这一行去掉,也没有闪退的情况了,但是任然会报一个错:
<dir style="color:red"> QObject::setParent: Cannot set parent, new parent is in a different thread </dir>但是这不影响正常使用。
有个问题,就是我把update()去掉以后,进度条就没有之前那样丝滑的动画了,我希望保留。
请问该怎么解决?