slots/signals with QNetworkReply
I cannot figure out how to properly use slots/signals when QNetworkReply detects an error.
I'm trying to detect a website that doesn't exist and I'd like to see "host not found" error.
This is the main code:
Code:
QNetworkAccessManager* nam; QNetworkReply* reply;
nam = new QNetworkAccessManager(this);
QObject::connect(reply,
SIGNAL(error
(QNetworkReply
::NetworkError)),
this,
SLOT(slotError
(QNetworkReply
::NetworkError)));
QUrl url; url.
setUrl("http://www.random-wrong-website.com");
reply = nam->get(QNetworkRequest(url));
Here's my slot slotError()
Code:
void MyClass::slotError(QNetworkReply* reply)
{
//extract the error code from here
}
My questions:
1) Am I calling the slot correctly? I have a feeling I don't have the parameters right.
2) Do you know how to find out (in slotError()) what the error code was
Please help if you can. Thanks!!
Re: slots/signals with QNetworkReply
Replace this line in slot definition.
Quote:
Originally Posted by
timmu
void MyClass::slotError(QNetworkReply* reply)
With
Code:
void MyClass::slotError(QNetworkReply::NetworkError err)
Re: slots/signals with QNetworkReply
thanks!
But what would be the slotError() prototype declaration in the h file? These don't work:
Code:
void slotError(class QNetworkReply);
or
void slotError(QNetworkReply::NetworkError err);
Re: slots/signals with QNetworkReply
The slot signature should match the signal you want to connect it to ...