Is there generic method to get the network error string out of the enum NetworkError or do i need to build one ?



  • I have basic function that prints network errors based on enum NetworkError.
    that looks like this :
    @void HttpClient::HandleNetworkError(QNetworkReply::NetworkError& networkError)
    {
    switch(networkError)
    {
    case(QNetworkReply::ConnectionRefusedError):
    LOG_MSG("NO NETWORK CONNECTION ConnectionRefusedError!! ");
    break;
    case(QNetworkReply::HostNotFoundError):
    //handle the html output is no internet connection is found
    LOG_MSG("NO NETWORK CONNECTION HostNotFoundError!! ");
    break;
    case(QNetworkReply::SslHandshakeFailedError):
    //handle the html output is no internet connection is found
    LOG_MSG("CONNECTION SslHandshakeFailedError!! ");
    break;
    case(QNetworkReply::UnknownContentError):
    LOG_MSG("CONNECTION UnknownContentError!! ");
    break;
    default :
    LOG_MSG("CONNECTION not defined default error UnknownContentError!! ");
    }

    }@

    now i need to support more errors , in fact all the error that list in enum NetworkError, so does it means i need to
    added them all to this switch case ? or there is some kind of generic Qt functions that do this translation ?


  • Moderators

    under the "signal error":http://developer.qt.nokia.com/doc/qt-4.8/qnetworkreply.html#error-2
    you can find
    [quote] The code parameter contains the code of the error that was detected. Call errorString() to obtain a textual representation of the error condition. [/quote]
    Did you try errorString() ?



  • well im using sync http request like this :
    @ QNetworkReply *reply = networkManager->get(request);
    connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();
    //return response
    ByteArrayResponse=reply->readAll();
    QNetworkReply::NetworkError networkError = reply->error();
    HandleNetworkError(networkError); @

    so i dont think i can use it ? or i can ?


  • Moderators

    I would give it a try. Since it is part of the docs for QNetworkReply it should work. Otherwise it is a bug in the docs and should be reported.



  • but how ... ?


  • Moderators

    When you "list all members of QNertworkReply":http://developer.qt.nokia.com/doc/qt-4.8/qnetworkreply-members.html there is an entry errorString()
    So this should work
    @
    QString str = reply->errorString();
    @

    errorString is a member function of QIODevice and QNetworkReply inherits QIODevice.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.