×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    29

    Host not found error on second application start.

    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_H
    Code:
    #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);
    }
    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;
    }
    Any help is greatly appreciated. Am I misusing the APIs? Not cleaning up correctly?

    Cheers,

    Wolfgang

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    29

    Re: Host not found error on second application start.

    I reported a bug on the qt issue tracker, because one of the qt examples (googlesuggest) that uses the QNetworkAccessManager has the same problem. See: http://bugreports.qt.nokia.com/browse/QTBUG-8335

    E72 is no exception, but had a data connection opened permanently which affected the issue positively.

  3. #3
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Host not found error on second application start.

    Few minor notes: why do you declare empty destructor and make it virtual. It's already virtual. In main function you can avoid using dynamic memory allocation. Since you don't have any UI you can use QCoreApplication instead of QApplication.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    29

    Re: Host not found error on second application start.

    @divanov, thanks for the notes.

    FYI: I tried using RHostResolver to get the IP address and use that to make the request. This gives the same error, because RHostResolver is not able to resolve the host name on the second application start.

  5. #5
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Host not found error on second application start.

    Quote Originally Posted by WolfgangDamm View Post
    FYI: I tried using RHostResolver to get the IP address and use that to make the request. This gives the same error, because RHostResolver is not able to resolve the host name on the second application start.
    That means that bug
    http://bugreports.qt.nokia.com/browse/QTBUG-8335
    is invalid.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    29

    Re: Host not found error on second application start.

    I don't think that the bug is invalid. Making connections only via the symbian APIs works (as tested in a lot of applications). It seems Qt or some library it uses (e.g. Open C) messes up the host resolver.

    Other application (e.g. built in browser) are still able to make connection via the host name.

  7. #7
    Nokia Developer Champion
    Join Date
    Jan 2010
    Posts
    6

    Re: Host not found error on second application start.

    The bug IS VALID !

    I have the same problems of Wolfgang.

    I must restart the phone to solve. The bug affects only QT application becouse browser ora other application still connect to internet.

    Please fix it !

    thank's

  8. #8
    Registered User
    Join Date
    Jun 2009
    Posts
    3

    Re: Host not found error on second application start.

    Hi,

    waiting for fix I wrote a class ( S60QHttp ) to tackle the problem.

    http://api.witinside.net/mobile/qt/s...FoundError.php

  9. #9
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Host not found error on second application start.

    That bug is listed as "closed -- cannot reproduce".

  10. #10
    Registered User
    Join Date
    Mar 2010
    Posts
    61

    Re: Host not found error on second application start.

    Could it be connected to this: http://bugreports.qt.nokia.com/browse/QTBUG-8687 ?

  11. #11
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Host not found error on second application start.

    Similar to problems I've seen. Eventually it seems you can get a solid connection, but it may take a dozen tries before enrolling a given access point will "take" permanently.

Similar Threads

  1. How to start to do a mobile application
    By mobiledevelopment in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2009-05-30, 12:31
  2. How to create a sis using ensymble and Python 1.9.4 ?
    By marcelobarrosalmeida in forum Symbian
    Replies: 10
    Last Post: 2009-05-27, 10:16
  3. Replies: 14
    Last Post: 2008-12-03, 10:22
  4. Start a J2ME application by OTA
    By hbfornies in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2003-09-24, 17:14

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×