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:
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));
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));
To copy to clipboard, switch view to plain text mode
Here's my slot slotError()
void MyClass::slotError(QNetworkReply* reply)
{
//extract the error code from here
}
void MyClass::slotError(QNetworkReply* reply)
{
//extract the error code from here
}
To copy to clipboard, switch view to plain text mode
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!!
Bookmarks