Search code examples
qtqt5pyqt5qnetworkaccessmanagerqnetworkreply

Where did file downloaded with PyQt5 network access manager go? And how do I save it?


Without specifying file to save, I created this:

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))

The last function I mentioned did write received byte. So, the is downloaded. Where did it go without I specified path to save? And How can I save it?


Solution

  • The reply is a QNetworkReply, which is subclass of QIODevice. So, it is roughly equivalent to the file-like objects found in python.

    Once the file has downloaded, you should be able to do something like:

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

    which will give you a python byte-string that can be saved to disk in the usual way.