PDA

View Full Version : QNetworkAccessManager::head not working



jonks
21st October 2009, 08:21
I have some code like this:



QNetworkAccessManager nam;
QNetworkRequest request(url);
m_reply = nam.head(request);

connect(m_reply, SIGNAL(readyRead()), this, SLOT(gotNetworkHeader()));
connect(m_reply, SIGNAL(finished(QNetworkReply*)), this, SLOT(headFinished(QNetworkReply*)));


readyRead and finished are never signaled.
Does anyone know why?:confused:

wysota
21st October 2009, 09:50
Sure. Your object goes out of scope and is destroyed.

jonks
21st October 2009, 23:19
Sure. Your object goes out of scope and is destroyed.

m_reply is already class scope, but the QNetworkAccessManager object was not.
I just moved it to class scope, but It still does not work.

In the constuctor:

{
...
m_nam = new QNetworkAccessManager(this);
...
}

In a class method:




{
m_reply = m_nam->head(QNetworkRequest(url));
connect(m_reply, SIGNAL(readyRead()), this, SLOT(gotNetworkHeader()));
}


There are are no runtime errors reported by when the connect function is called.

...But still no signal is emitted???

wysota
21st October 2009, 23:23
Do you remember to run the event loop? Does the same request using get instead of head finishes correctly?

jonks
21st October 2009, 23:23
I got it

readReady() is the wrong signal.
I should have been connecting the finished() signal.

I now works.
Of course wysota - putting QNetworkAccessManager at class scope is required too.
Thanks