QNetworkReply readAll() gets empty data on finished()
-
Hi,
didn't see you replied here. I am unable to fix it, even when storing link to QNetworkReply - and check whenever sender() is this reply.
It seems that buffer is somehow read in inner slot, before emitting finish(). and it doesnt matter if it is emitted by QNR or QNAM.
It seems not only me has same problem: "http://qt-project.org/forums/viewthread/51848/":http://qt-project.org/forums/viewthread/51848/
Edit: it seems to have something to do with windows, not code. Maybe some point here?
@'Sample.exe': Loaded 'C:\Windows\SysWOW64\WSHTCPIP.DLL', Cannot find or open the PDB file
QVariant(Invalid)
'Sample.exe': Unloaded 'C:\Windows\SysWOW64\WSHTCPIP.DLL'
@ -
@Almer_Cz
i meet the problem to with release version,
but with debug version every this is ok.
Qt 4.8.6
....... -
@p3c0 said in QNetworkReply readAll() gets empty data on finished():
request
Hello,
I wake up this topic because I had exactly the same issue, because I may found the origin of the problem.
I have those error in the application output (still have them, and I use only http request) :
qt.network.ssl: QSslSocket: cannot resolve SSL_set_alpn_protos qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_alpn_select_cb qt.network.ssl: QSslSocket: cannot resolve SSL_get0_alpn_selected
This bug report says that those errors are relevant, but I have remove OpenVPN that use OpenSSL and OpenMG but it doesn't seems related.
I am using Qt 5.9.2 on Windows 10 64bits.
I still have few troubles to print the content, some times the print disappear or is cut, but I know that it is good with the debugger or simply because the parsing after is working fine.
QByteArray content = reply->readAll(); qDebug() << "Status Code: " << statusCode; qDebug() << "Content length: " << contentLength; qDebug() << "Content type: " << contentType; qDebug() << "Redirect target url: " << redirectionTargetUrl; qDebug() << "Response:\n" << content; // No always full ("Response:" text can be cut too???)
PS: Too me it seems to be black magic.
Serie::Serie() : mNetworkAccessManager(new QNetworkAccessManager) { QObject::connect(mNetworkAccessManager, &QNetworkAccessManager::finished, this, &Serie::onLoadFinished); } Serie::~Serie() { QObject::disconnect(mNetworkAccessManager, &QNetworkAccessManager::finished, this, &Serie::onLoadFinished); delete mNetworkAccessManager; } void Serie::searchAddictedId() { mNetworkAccessManager->get(QNetworkRequest(QUrl("http://google.fr"))); } void Serie::onLoadFinished(QNetworkReply* reply) { if (reply->error() != QNetworkReply::NoError) { qDebug() << reply->errorString(); reply->deleteLater(); return; } int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); int contentLength = reply->header(QNetworkRequest::ContentLengthHeader).toInt(); QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); QUrl redirectionTargetUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); QByteArray content = reply->readAll(); qDebug() << "Status Code: " << statusCode; qDebug() << "Content length: " << contentLength; qDebug() << "Content type: " << contentType; qDebug() << "Redirect target url: " << redirectionTargetUrl; qDebug() << "Response:\n" << content.toStdString().c_str(); if (redirectionTargetUrl.isEmpty() == false) { qDebug() << "Redirect to: " << redirectionTargetUrl; mNetworkAccessManager->get(QNetworkRequest(redirectionTargetUrl)); reply->deleteLater(); return; } QXmlStreamReader xml; xml.addData(content); .... reply->deleteLater(); }
-
Hello,
I´ve had the same problem, made a request,got a reply with a 200 status code. But if i tried to qDebug() nothing would happen. However I wrote the data into a .txt file an then opened it, and the html code was there. So it seems like it is not possible for qDebug() to print the data.I hope this will save some time for you guys having the same problem.
-
Welcome, and thanks for sharing your solution!
@Taras-Ertl said in QNetworkReply readAll() gets empty data on finished():
So it seems like it is not possible for qDebug() to print the data.
There seems to be a limit to the amount of text that can be printed to Qt Creator's "Application Output" panel. If you try to print too much text to qDebug at once, nothing will appear (I'm not sure if this is a bug or not).
Your workaround of printing to a text file instead is good.