PDA

View Full Version : slots/signals with QNetworkReply



timmu
24th August 2009, 14:03
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));


Here's my slot slotError()


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!!

yogeshgokul
24th August 2009, 14:11
Replace this line in slot definition.


void MyClass::slotError(QNetworkReply* reply)


With

void MyClass::slotError(QNetworkReply::NetworkError err)

timmu
24th August 2009, 15:19
thanks!

But what would be the slotError() prototype declaration in the h file? These don't work:



void slotError(class QNetworkReply);
or
void slotError(QNetworkReply::NetworkError err);

aamer4yu
24th August 2009, 15:26
The slot signature should match the signal you want to connect it to ...