PDA

View Full Version : QNetworkAccessManager unknown error



lipk
20th March 2011, 08:41
Hi all!

I have almost become a nervous wreck already because of this thing:



#include <QtCore/QCoreApplication>
#include <QtNetwork>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QNetworkAccessManager manager;
QNetworkRequest request(QUrl("http://www.google.hu"));

QNetworkReply *reply = manager.get(request);

qDebug() << reply->errorString();
return a.exec();
}


It's that simple. And it doesn't work. It says: "Unknown error".

Bad code? Bad proxy settings? What? Nokia's HTTP example works fine.

squidge
20th March 2011, 12:12
manager.get is asynchronous, it's likely that the request has only been posted and not even started by the time the reply->errorString() is executed, and thus, "Unknown error".

Use signals and slots and you'll be told when the request has actually been executed, and THEN you can request the error code, if any.

lipk
20th March 2011, 13:38
Oh. I thought if I can get any error message then there's an error...
Finally I got it working. Thanks.