1

没有指定要保存的文件,我创建了这个:

def start_download(self):
    self.reply = self.manager.get(QNetworkRequest(QUrl(self.url_edit.text())))
    self.reply.downloadProgress.connect(self.download_progress)
    self.label.setText(self.url_edit.text())

def download_progress(self, received, total):
    print(received, type(received))

我提到的最后一个函数确实写入了接收到的字节。于是,就下载好了。如果我没有指定保存路径,它去了哪里?我怎样才能保存它?

4

1 回答 1

2

回复是QNetworkReply,它是QIODevice的子类。因此,它大致相当于 python 中的类文件对象。

文件下载后,您应该能够执行以下操作:

    data = self.reply.readAll().data()

这将为您提供一个可以以通常方式保存到磁盘的python字节字符串。

于 2015-05-14T22:31:58.070 回答