How to download using QHttp? But file should not be saved in the local hard disk, It has to save in some memory variable, How to to this?
How to download using QHttp? But file should not be saved in the local hard disk, It has to save in some memory variable, How to to this?
Don't use QHttp in new code. To quote the docs:
You use QNetworkAccessManager and QNetworkReply::read() or readAll() the data into a QByteArrayThis class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
I have used QHttp for downloading it, now the file is being downloaded , and saved in the local disk, But i just want to read that file, storing it in a variable, and not saving it as a file in local hard disk. How to perform this with QHttp??
I'd use readAll rather than specifying the i/o device in the request.
But as ChrisW67 says, you should be using QNetworkAccessManager, as QHttp is deprecated.
Check out the "HTTP Client" example.
on the QNetworkReply::finished signal call reply->readAll() if the data is human readable you can do something like
Qt Code:
QString replyString; if (reply->isReadable()) { }To copy to clipboard, switch view to plain text mode
Even if you persist in using the obsolete class you can use QHttp::readAll() to put the data into a QByteArray (either bit-by-bit using in response to readyRead(), or all at once in response to finished()). That is, use exactly the same method as used in the HTTP Example. This information really easy to find if you read the docs and work through the examples (until you understand them).
How to read the whole file at once using readAll()?
Wait until the QNetworkReply::finished() or QNetworkAccessManager::finished() signal is emitted and then call readAll(). If you are still using QHttp then you can work out the equivalent for yourself.
If your file is large, or you don't know its size, then trying to hold the whole thing in memory might be a mistake.
Bookmarks