QNetworkReply Class

The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager. More...

Header: #include <QNetworkReply>
qmake: QT += network
Since: Qt 4.4
Inherits: QIODevice

This class was introduced in Qt 4.4.

Note: All functions in this class are reentrant.

Public Types

enum NetworkError { NoError, ConnectionRefusedError, RemoteHostClosedError, HostNotFoundError, TimeoutError, …, UnknownServerError }
typedef RawHeaderPair

Detailed Description

The QNetworkReply class contains the data and meta data related to a request posted with QNetworkAccessManager. Like QNetworkRequest, it contains a URL and headers (both in parsed and raw form), some information about the reply's state and the contents of the reply itself.

QNetworkReply is a sequential-access QIODevice, which means that once data is read from the object, it is no longer kept by the device. It is therefore the application's responsibility to keep this data if it needs to. Whenever more data is received from the network and processed, the readyRead() signal is emitted.

The downloadProgress() signal is also emitted when data is received, but the number of bytes contained in it may not represent the actual bytes received, if any transformation is done to the contents (for example, decompressing and removing the protocol overhead).

Even though QNetworkReply is a QIODevice connected to the contents of the reply, it also emits the uploadProgress() signal, which indicates the progress of the upload for operations that have such content.

Note: Do not delete the object in the slot connected to the errorOccurred() or finished() signal. Use deleteLater().

See also QNetworkRequest and QNetworkAccessManager.

Member Type Documentation

enum QNetworkReply::NetworkError

Indicates all possible error conditions found during the processing of the request.

ConstantValueDescription
QNetworkReply::NoError0no error condition.

Note: When the HTTP protocol returns a redirect no error will be reported. You can check if there is a redirect with the QNetworkRequest::RedirectionTargetAttribute attribute.

ConstantValueDescription
QNetworkReply::ConnectionRefusedError1the remote server refused the connection (the server is not accepting requests)
QNetworkReply::RemoteHostClosedError2the remote server closed the connection prematurely, before the entire reply was received and processed
QNetworkReply::HostNotFoundError3the remote host name was not found (invalid hostname)
QNetworkReply::TimeoutError4the connection to the remote server timed out
QNetworkReply::OperationCanceledError5the operation was canceled via calls to abort() or close() before it was finished.
QNetworkReply::SslHandshakeFailedError6the SSL/TLS handshake failed and the encrypted channel could not be established. The sslErrors() signal should have been emitted.
QNetworkReply::TemporaryNetworkFailureError7the connection was broken due to disconnection from the network, however the system has initiated roaming to another access point. The request should be resubmitted and will be processed as soon as the connection is re-established.
QNetworkReply::NetworkSessionFailedError8the connection was broken due to disconnection from the network or failure to start the network.
QNetworkReply::BackgroundRequestNotAllowedError9the background request is not currently allowed due to platform policy.
QNetworkReply::TooManyRedirectsError10while following redirects, the maximum limit was reached. The limit is by default set to 50 or as set by QNetworkRequest::setMaxRedirectsAllowed(). (This value was introduced in 5.6.)
QNetworkReply::InsecureRedirectError11while following redirects, the network access API detected a redirect from a encrypted protocol (https) to an unencrypted one (http). (This value was introduced in 5.6.)
QNetworkReply::ProxyConnectionRefusedError101the connection to the proxy server was refused (the proxy server is not accepting requests)
QNetworkReply::ProxyConnectionClosedError102the proxy server closed the connection prematurely, before the entire reply was received and processed
QNetworkReply::ProxyNotFoundError103the proxy host name was not found (invalid proxy hostname)
QNetworkReply::ProxyTimeoutError104the connection to the proxy timed out or the proxy did not reply in time to the request sent
QNetworkReply::ProxyAuthenticationRequiredError105the proxy requires authentication in order to honour the request but did not accept any credentials offered (if any)
QNetworkReply::ContentAccessDenied201the access to the remote content was denied (similar to HTTP error 403)
QNetworkReply::ContentOperationNotPermittedError202the operation requested on the remote content is not permitted
QNetworkReply::ContentNotFoundError203the remote content was not found at the server (similar to HTTP error 404)
QNetworkReply::AuthenticationRequiredError204the remote server requires authentication to serve the content but the credentials provided were not accepted (if any)
QNetworkReply::ContentReSendError205the request needed to be sent again, but this failed for example because the upload data could not be read a second time.
QNetworkReply::ContentConflictError206the request could not be completed due to a conflict with the current state of the resource.
QNetworkReply::ContentGoneError207the requested resource is no longer available at the server.
QNetworkReply::InternalServerError401the server encountered an unexpected condition which prevented it from fulfilling the request.
QNetworkReply::OperationNotImplementedError402the server does not support the functionality required to fulfill the request.
QNetworkReply::ServiceUnavailableError403the server is unable to handle the request at this time.
QNetworkReply::ProtocolUnknownError301the Network Access API cannot honor the request because the protocol is not known
QNetworkReply::ProtocolInvalidOperationError302the requested operation is invalid for this protocol
QNetworkReply::UnknownNetworkError99an unknown network-related error was detected
QNetworkReply::UnknownProxyError199an unknown proxy-related error was detected
QNetworkReply::UnknownContentError299an unknown error related to the remote content was detected
QNetworkReply::ProtocolFailure399a breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.)
QNetworkReply::UnknownServerError499an unknown error related to the server response was detected

See also error() and errorOccurred().

typedef QNetworkReply::RawHeaderPair

RawHeaderPair is a QPair<QByteArray, QByteArray> where the first QByteArray is the header name and the second is the header.