QNetworkReply::readAll always returns null, how to get the data downloaded?
-
I'm trying to download a file:
@QNetworkRequest request;
request.setUrl(QUrl(fileUrl));
QNetworkReply * reply = m_nam.get(request);
connect(reply, SIGNAL(finished()), this, SLOT(onDownloadRequestFinished()), Qt::UniqueConnection);
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(onDownloadRequestProgress(qint64, qint64)), Qt::UniqueConnection);@And in the onDownloadRequestFinished slot:
@QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
if (reply && reply->error() == QNetworkReply::NoError) {
Q_ASSERT(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200);
qDebug() << "reply " << reply->bytesAvailable() << reply->pos() << reply->size() << reply->isReadable() << reply->openMode() << reply->isOpen();
}@The slot prints the following: "reply 0 0 0 true OpenMode( "ReadOnly" ) true". So, no data. However, I can clearly see that it does download something somewhere. It's a big file and it does download it, judging from onDownloadRequestProgress (the time it takes and the calculated speed matches the file size and my internet connection speed perfectly).
Where's the data?
-
Try connecting the QNetworkReply::readyRead() signal to a slot and read the data there.
-
Did you try examples\network\download ?
Try it if you did not try. -
I will. Is there anything wrong with my approach?
By the way, a very important note: the code snippet from my question works in some parts of my project! But not the others. Exactly the same algorithm.