Important: Please read the Qt Code of Conduct -

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)
    LOG_MSG("NO NETWORK CONNECTION ConnectionRefusedError!! ");
    //handle the html output is no internet connection is found
    LOG_MSG("NO NETWORK CONNECTION HostNotFoundError!! ");
    //handle the html output is no internet connection is found
    LOG_MSG("CONNECTION SslHandshakeFailedError!! ");
    LOG_MSG("CONNECTION UnknownContentError!! ");
    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 ?

  • under the "signal error":
    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()));
    //return response
    QNetworkReply::NetworkError networkError = reply->error();
    HandleNetworkError(networkError); @

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

  • 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 ... ?

  • When you "list all members of QNertworkReply": 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