Is there generic method to get the network error string out of the enum NetworkError or do i need to build one ?
-
wrote on 27 Feb 2012, 09:57 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 ? -
wrote on 27 Feb 2012, 10:16 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() ? -
wrote on 27 Feb 2012, 10:36 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 ?
-
wrote on 27 Feb 2012, 10:45 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.
-
wrote on 27 Feb 2012, 12:30 last edited by
but how ... ?
-
wrote on 27 Feb 2012, 12:35 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.
1/6