PDA

View Full Version : readyRead signal is not emitted



gig-raf
15th February 2016, 15:21
Dear All,

I have a small QT application that checks things from a web site. All was working fine some days ago, but all of the sudden my readyRead() SIGNAL is never emitted. That is my finished() signal is called before the readyRead().

That is bad because I then get an empty HTML page back! ;-)

My code does work with other web-sites, all I do is something very simple:



#include <QtNetwork>

void myClass::startRequest(QUrl url,bool urlType)
{
QNetworkRequest request;
request.setUrl(QUrl(url));
request.setRawHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Firefox/31.0");
reply = qnam.get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
connect(reply, SIGNAL(finished()), this, SLOT(httpFinished2()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(httpError(QNetworkReply::NetworkError)));
}


so if I comment out the readyRead connect the application just hangs forever. If I uncomment it again the finished() signal is emitted shorty after, the httpReadyRead() is NEVER called.

how can I troubleshoot this?

thanks for any help you may offer...

cheers!

Added after 26 minutes:

Okay, after investigating I realize that the there was a redirect that was not caught by my app.


QVariant rUrl = httpReply->attribute(QNetworkRequest::RedirectionTargetAttrib ute);
qDebug() << rUrl;

jefftee
15th February 2016, 23:50
What is the http status code when your finished signal is called? i.e. look at QNetworkReply::attribute with QNetworkRequest::HttpStatusCodeAttribute.

Edit: didn't see your edit until after I posted... Tip is still valid though, when dealing with HTTP requests, always know the http status code... :)

gig-raf
16th February 2016, 08:13
Thanks for your reply! Yes you are absolutely right.