Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    6
    8877
    Loading More Posts
    • 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
      umen242 last edited by

      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 Reply Quote 0
      • K
        koahnig last edited by

        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 Reply Quote 0
        • U
          umen242 last edited by

          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 Reply Quote 0
          • K
            koahnig last edited by

            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 Reply Quote 0
            • U
              umen242 last edited by

              but how ... ?

              1 Reply Last reply Reply Quote 0
              • K
                koahnig last edited by

                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 Reply Quote 0
                • First post
                  Last post