Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a QNetworkReply to a file

Tags:

c++

qt

I'm downloading a file using QNetworkAccessManager::get but unlike QHttp::get there's no built-in way to directly write the response to a different QIODevice.

The easiest way would be to do something like this:

QIODevice* device;

QNetworkReply* reply = manager.get(url);
connect(reply, SIGNAL(readyRead()), this, SLOT(newData()));

and then in newData slot:

device->write(reply->readAll());

But I'm not sure if this is the right way, maybe I missed something.

like image 748
Idan K Avatar asked Jul 30 '09 09:07

Idan K


1 Answers

That looks correct. I would use the lower-level forms of read() and write(), not the QByteArray ones, which do not properly support error handling, but other than that, it looks fine.

Are you having problems with it?

like image 161
Marc Mutz - mmutz Avatar answered Sep 28 '22 06:09

Marc Mutz - mmutz