Hi,
SI am making an HTTP Get request to a server using QNetworkAccessManager which works fine for the first application start. Restarting the application yields an "Host not found" error when the request is made. Other native Symbian application are still able to connect to that server! Everything works fine the first (sometimes 2nd) application start. There is no problem requesting data multiple times from the server during one application session.
The error occurs each time thereafter until I restart the device. It only occurs if I'm using the cellular network. WLAN works fine. I tested this on N97 and N86 with the same result. The E72 does not yield this error (Probably configuration differences?!). I have tried almost everything and have no idea what is going wrong.
I use following tools and APIs:
- Qt 4.6.2
- S60 5th Edition SDK
- S60 3rd Edition FP 2 SDK (v1.1)
Here is the stripped down source I'm using to reproduce the error.
Code:#ifndef REQUESTOR_H #define REQUESTOR_H #include <QObject> #include <QNetworkReply> class QNetworkAccessManager; class QNetworkReply; class Requestor : public QObject { Q_OBJECT public: Requestor(); virtual ~Requestor(); public slots: void makeRequest(); private slots: void handleFinished(); void handleError(QNetworkReply::NetworkError aCode); private: QNetworkAccessManager* iNetworkAccessManager; QNetworkReply* iReply; }; #endif // REQUESTOR_HCode:#include <QUrl> #include <QNetworkRequest> #include <QNetworkReply> #include <QByteArray> #include <QMessageBox> #include <QNetworkAccessManager> #include <QApplication> #include "Requestor.h" Requestor::Requestor() : iNetworkAccessManager(NULL),iReply(NULL) { iNetworkAccessManager = new QNetworkAccessManager(this); } Requestor::~Requestor() { } void Requestor::makeRequest() { QUrl aUrl("http://www.google.com"); QNetworkRequest request(aUrl); iReply = iNetworkAccessManager->get(request); connect(iReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(handleError(QNetworkReply::NetworkError))); connect(iReply, SIGNAL(finished()), this, SLOT(handleFinished())); } void Requestor::handleFinished() { if (!iReply) return; int statusCode = iReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QMessageBox msg(QMessageBox::Information, "StatusCode", QString("StatusCode: %1").arg(statusCode), QMessageBox::Ok); msg.exec(); QByteArray bytes = iReply->readAll(); QMessageBox msg2(QMessageBox::Information, "Message", QString(bytes).arg(statusCode), QMessageBox::Ok); msg2.exec(); iReply->deleteLater(); iReply = NULL; } void Requestor::handleError(QNetworkReply::NetworkError aCode) { int statusCode = iReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QString errorStr(iReply->errorString()); iReply->deleteLater(); iReply = NULL; QMessageBox msg(QMessageBox::Warning, "Error", QString("Error %1 (Status: %2): %3").arg(aCode).arg(statusCode).arg(errorStr), QMessageBox::Ok); msg.exec(); QApplication::exit(-1); }Any help is greatly appreciated. Am I misusing the APIs? Not cleaning up correctly?Code:#include <QApplication> #include <QMessageBox> #include "Requestor.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Requestor* r = new Requestor(); r->makeRequest(); int ret = a.exec(); delete r; return ret; }
Cheers,
Wolfgang





