6.0.0-rc4Source

QNetworkReply Class

The QNetworkReply class holds the response to a QNetworkAccessManager request. More…

Header#include <QNetworkReply>
CMaketarget_link_libraries(app PRIVATE Nt::Network)
ModuleNt Network C++ Classes
InheritsQIODevice

List of all members, including inherited members

Public Types

Public Functions

Reimplemented Public Functions

boolisSequential() const
qint64bytesAvailable() const
boolcanReadLine() const
boolatEnd() const
voidclose()

Public Slots

virtual voidabort()
virtual voidignoreSslErrors()

Signals

voidfinished()
voiderrorOccurred(QNetworkReply::NetworkError code)
voidmetaDataChanged()
voidredirected(const QUrl &url)
voiduploadProgress(qint64 bytesSent, qint64 bytesTotal)
voiddownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
voidencrypted()
voidsslErrors(const QList<QSslError> &errors)

Protected Functions

QNetworkReply(QObject *parent = nullptr)

Reimplemented Protected Functions

qint64readData(char *data, qint64 maxSize)
qint64writeData(const char *data, qint64 maxSize)

Detailed Description

A reply is a sequential QIODevice. Data becomes readable as it arrives, and finished() is emitted once at the end, on success or failure. An HTTP error status such as 404 sets error(), and its body stays readable.

See also QNetworkAccessManager and QNetworkRequest.

Differences from Qt

Only the attributes listed under QNetworkRequest::Attribute as reply attributes are produced; the others read back what the request stored. header() returns QByteArray. Unlike Qt, the whole response stays buffered until read, with no read buffer limit. There are no proxy errors, as proxies do not exist yet.

Member Type Documentation

enum QNetworkReply::NetworkError

Describes how a reply failed.

ConstantDescription
QNetworkReply::NoErrorThe request succeeded.
QNetworkReply::ConnectionRefusedErrorThe server refused the connection.
QNetworkReply::RemoteHostClosedErrorThe server closed the connection before the reply was complete.
QNetworkReply::HostNotFoundErrorThe host name could not be resolved.
QNetworkReply::TimeoutErrorThe transfer timed out.
QNetworkReply::OperationCanceledErrorabort() was called.
QNetworkReply::SslHandshakeFailedErrorThe TLS handshake failed, or the server could not be verified.
QNetworkReply::TemporaryNetworkFailureErrorNot used.
QNetworkReply::NetworkSessionFailedErrorNot used.
QNetworkReply::BackgroundRequestNotAllowedErrorNot used.
QNetworkReply::TooManyRedirectsErrorThe redirect limit was reached.
QNetworkReply::InsecureRedirectErrorThe redirect policy refused a redirect.
QNetworkReply::UnknownNetworkErrorAnother network error occurred.
QNetworkReply::ContentAccessDeniedThe server replied 403.
QNetworkReply::ContentOperationNotPermittedErrorThe server replied 405.
QNetworkReply::ContentNotFoundErrorThe server replied 404.
QNetworkReply::AuthenticationRequiredErrorThe server replied 401.
QNetworkReply::ContentReSendErrorNot used.
QNetworkReply::ContentConflictErrorThe server replied 409.
QNetworkReply::ContentGoneErrorThe server replied 410.
QNetworkReply::UnknownContentErrorThe server replied with another 4xx status.
QNetworkReply::ProtocolUnknownErrorThe URL's scheme is not supported, or the URL is invalid.
QNetworkReply::ProtocolInvalidOperationErrorThe request itself is malformed.
QNetworkReply::ProtocolFailureThe server sent an invalid response.
QNetworkReply::InternalServerErrorThe server replied 500.
QNetworkReply::OperationNotImplementedErrorThe server replied 501.
QNetworkReply::ServiceUnavailableErrorThe server replied 503.
QNetworkReply::UnknownServerErrorThe server replied with another 5xx status.

Member Function Documentation

[explicit, protected] QNetworkReply::QNetworkReply(QObject *parent = nullptr)

Constructs a reply with the given parent.

[override] QNetworkReply::~QNetworkReply()

Destroys the reply, abandoning the transfer if it is still running.

[slot, virtual] void QNetworkReply::abort()

Stops the transfer. The reply finishes with OperationCanceledError.

[override] bool QNetworkReply::atEnd() const

Reimplements QIODevice::atEnd().

QVariant QNetworkReply::attribute(QNetworkRequest::Attribute code) const

Returns the attribute for code, or an invalid QVariant if it has none. Status, reason, redirect target and encryption are taken from the response; any other code returns what the request stored with QNetworkRequest::setAttribute(), which is how applications tag a request and find the tag again in the reply.

See also httpStatusCode() and request().

[override] qint64 QNetworkReply::bytesAvailable() const

Reimplements QIODevice::bytesAvailable().

[override] bool QNetworkReply::canReadLine() const

Reimplements QIODevice::canReadLine().

[override] void QNetworkReply::close()

Reimplements QIODevice::close().

[signal] void QNetworkReply::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)

This signal is emitted as data arrives, with bytesReceived of bytesTotal bytes done. bytesTotal is -1 if the size is unknown.

[signal] void QNetworkReply::encrypted()

This signal is emitted when the TLS handshake has finished.

NetworkError QNetworkReply::error() const

Returns the error, or NoError if there has been none.

See also errorOccurred().

[signal] void QNetworkReply::errorOccurred(QNetworkReply::NetworkError code)

This signal is emitted just before finished() when the reply fails with code.

[signal] void QNetworkReply::finished()

This signal is emitted when the reply has finished, whether it succeeded or not. It is emitted exactly once.

bool QNetworkReply::hasRawHeader(const QByteArray &headerName) const

Returns true if the response has the header headerName. Names are not case sensitive.

Returns the value of the known header.

See also rawHeader().

QByteArray QNetworkReply::httpReasonPhrase() const

Returns the HTTP reason phrase.

See also httpStatusCode().

int QNetworkReply::httpStatusCode() const

Returns the HTTP status code, or 0 if none has been received.

See also httpReasonPhrase().

[virtual] void QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors)

Continues despite the errors listed, and no others. Call this before the handshake or from a slot connected to sslErrors(). It does not carry over to a redirect that leaves the origin.

[slot, virtual] void QNetworkReply::ignoreSslErrors()

This is an overloaded function.

Continues despite every verification problem. Call this from a slot connected to sslErrors(). It removes the protection TLS gives against impersonation, and does not carry over to a redirect that leaves the origin.

bool QNetworkReply::isFinished() const

Returns true once the reply has finished.

See also finished() and isRunning().

bool QNetworkReply::isRunning() const

Returns true while the request is in progress.

See also isFinished().

[override] bool QNetworkReply::isSequential() const

Reimplements QIODevice::isSequential().

QNetworkAccessManager * QNetworkReply::manager() const

Returns the manager that created the reply.

[signal] void QNetworkReply::metaDataChanged()

This signal is emitted when the response headers have been received.

QByteArray QNetworkReply::rawHeader(const QByteArray &headerName) const

Returns the value of the header headerName. Repeated headers are joined with ", ", or with a newline for Set-Cookie.

QList<QByteArray> QNetworkReply::rawHeaderList() const

Returns the names of the response headers.

QList<std::pair<QByteArray, QByteArray>> QNetworkReply::rawHeaderPairs() const

Returns the response headers in the order they were received.

[override, protected] qint64 QNetworkReply::readData(char *data, qint64 maxSize)

Reimplements QIODevice::readData().

[signal] void QNetworkReply::redirected(const QUrl &url)

This signal is emitted when a redirect to url is followed.

QNetworkRequest QNetworkReply::request() const

Returns the request this reply answers.

QSslConfiguration QNetworkReply::sslConfiguration() const

Returns the TLS details of the connection, once the handshake has finished.

[signal] void QNetworkReply::sslErrors(const QList<QSslError> &errors)

This signal is emitted if verifying the server found errors. Unless a connected slot calls ignoreSslErrors(), the reply fails.

[signal] void QNetworkReply::uploadProgress(qint64 bytesSent, qint64 bytesTotal)

This signal is emitted as the body is sent, with bytesSent of bytesTotal bytes done.

QUrl QNetworkReply::url() const

Returns the URL of the content that was fetched, which differs from the request's URL after a redirect.

See also request().

[override, protected] qint64 QNetworkReply::writeData(const char *data, qint64 maxSize)

Reimplements QIODevice::writeData().