Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there generic method to get the network error string out of the enum NetworkError or do i need to build one ?

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

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 9.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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() ?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #3

        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 ?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          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.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • U Offline
            U Offline
            umen242
            wrote on last edited by
            #5

            but how ... ?

            1 Reply Last reply
            0
            • K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              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.

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved