Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Functions | List of all members
QNetworkReply Class Referenceabstract

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

#include <qnetworkreply.h>

Inheritance diagram for QNetworkReply:
QIODevice QObject QDisabledNetworkReply QNetworkReplyDataImpl QNetworkReplyFileImpl QNetworkReplyImpl QPatternist::QIODeviceDelegate

Public Types

enum  NetworkError {
  NoError = 0, ConnectionRefusedError = 1, RemoteHostClosedError, HostNotFoundError,
  TimeoutError, OperationCanceledError, SslHandshakeFailedError, TemporaryNetworkFailureError,
  UnknownNetworkError = 99, ProxyConnectionRefusedError = 101, ProxyConnectionClosedError, ProxyNotFoundError,
  ProxyTimeoutError, ProxyAuthenticationRequiredError, UnknownProxyError = 199, ContentAccessDenied = 201,
  ContentOperationNotPermittedError, ContentNotFoundError, AuthenticationRequiredError, ContentReSendError,
  UnknownContentError = 299, ProtocolUnknownError = 301, ProtocolInvalidOperationError, ProtocolFailure = 399
}
 Indicates all possible error conditions found during the processing of the request. More...
 
typedef QPair< QByteArray, QByteArrayRawHeaderPair
 RawHeaderPair is a QPair<QByteArray, QByteArray> where the first QByteArray is the header name and the second is the header. More...
 
- Public Types inherited from QIODevice
enum  OpenModeFlag {
  NotOpen = 0x0000, ReadOnly = 0x0001, WriteOnly = 0x0002, ReadWrite = ReadOnly | WriteOnly,
  Append = 0x0004, Truncate = 0x0008, Text = 0x0010, Unbuffered = 0x0020
}
 This enum is used with open() to describe the mode in which a device is opened. More...
 

Public Slots

virtual void ignoreSslErrors ()
 If this function is called, SSL errors related to network connection will be ignored, including certificate validation errors. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void downloadProgress (qint64 bytesReceived, qint64 bytesTotal)
 This signal is emitted to indicate the progress of the download part of this network request, if there's any. More...
 
void error (QNetworkReply::NetworkError)
 This signal is emitted when the reply detects an error in processing. More...
 
void finished ()
 This signal is emitted when the reply has finished processing. More...
 
void metaDataChanged ()
 This signal is emitted whenever the metadata in this reply changes. More...
 
void sslErrors (const QList< QSslError > &errors)
 This signal is emitted if the SSL/TLS session encountered errors during the set up, including certificate verification errors. More...
 
void uploadProgress (qint64 bytesSent, qint64 bytesTotal)
 This signal is emitted to indicate the progress of the upload part of this network request, if there's any. More...
 
- Signals inherited from QIODevice
void aboutToClose ()
 This signal is emitted when the device is about to close. More...
 
void bytesWritten (qint64 bytes)
 This signal is emitted every time a payload of data has been written to the device. More...
 
void readChannelFinished ()
 This signal is emitted when the input (reading) stream is closed in this device. More...
 
void readyRead ()
 This signal is emitted once every time new data is available for reading from the device. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

virtual void abort ()=0
 Aborts the operation immediately and close down any network connections still open. More...
 
QVariant attribute (QNetworkRequest::Attribute code) const
 Returns the attribute associated with the code code. More...
 
virtual void close ()
 Closes this device for reading. More...
 
NetworkError error () const
 Returns the error that was found during the processing of this request. More...
 
bool hasRawHeader (const QByteArray &headerName) const
 Returns true if the raw header of name headerName was sent by the remote server. More...
 
QVariant header (QNetworkRequest::KnownHeaders header) const
 Returns the value of the known header header, if that header was sent by the remote server. More...
 
void ignoreSslErrors (const QList< QSslError > &errors)
 If this function is called, the SSL errors given in errors will be ignored. More...
 
bool isFinished () const
 Returns true when the reply has finished or was aborted. More...
 
bool isRunning () const
 Returns true when the request is still processing and the reply has not finished or was aborted yet. More...
 
virtual bool isSequential () const
 
QNetworkAccessManagermanager () const
 Returns the QNetworkAccessManager that was used to create this QNetworkReply object. More...
 
QNetworkAccessManager::Operation operation () const
 Returns the operation that was posted for this reply. More...
 
QByteArray rawHeader (const QByteArray &headerName) const
 Returns the raw contents of the header headerName as sent by the remote server. More...
 
QList< QByteArrayrawHeaderList () const
 Returns a list of headers fields that were sent by the remote server, in the order that they were sent. More...
 
const QList< RawHeaderPair > & rawHeaderPairs () const
 Returns a list of raw header pairs. More...
 
qint64 readBufferSize () const
 Returns the size of the read buffer, in bytes. More...
 
QNetworkRequest request () const
 Returns the request that was posted for this reply. More...
 
virtual void setReadBufferSize (qint64 size)
 Sets the size of the read buffer to be size bytes. More...
 
void setSslConfiguration (const QSslConfiguration &configuration)
 Sets the SSL configuration for the network connection associated with this request, if possible, to be that of config. More...
 
QSslConfiguration sslConfiguration () const
 Returns the SSL configuration and state associated with this reply, if SSL was used. More...
 
QUrl url () const
 Returns the URL of the content downloaded or uploaded. More...
 
 ~QNetworkReply ()
 Disposes of this reply and frees any resources associated with it. More...
 
- Public Functions inherited from QIODevice
virtual bool atEnd () const
 Returns true if the current read and write position is at the end of the device (i.e. More...
 
virtual qint64 bytesAvailable () const
 Returns the number of bytes that are available for reading. More...
 
virtual qint64 bytesToWrite () const
 For buffered devices, this function returns the number of bytes waiting to be written. More...
 
virtual bool canReadLine () const
 Returns true if a complete line of data can be read from the device; otherwise returns false. More...
 
QString errorString () const
 Returns a human-readable description of the last device error that occurred. More...
 
bool getChar (char *c)
 Reads one character from the device and stores it in c. More...
 
bool isOpen () const
 Returns true if the device is open; otherwise returns false. More...
 
bool isReadable () const
 Returns true if data can be read from the device; otherwise returns false. More...
 
bool isTextModeEnabled () const
 Returns true if the Text flag is enabled; otherwise returns false. More...
 
bool isWritable () const
 Returns true if data can be written to the device; otherwise returns false. More...
 
virtual bool open (OpenMode mode)
 Opens the device and sets its OpenMode to mode. More...
 
OpenMode openMode () const
 Returns the mode in which the device has been opened; i.e. More...
 
qint64 peek (char *data, qint64 maxlen)
 Reads at most maxSize bytes from the device into data, without side effects (i. More...
 
QByteArray peek (qint64 maxlen)
 Peeks at most maxSize bytes from the device, returning the data peeked as a QByteArray. More...
 
virtual qint64 pos () const
 For random-access devices, this function returns the position that data is written to or read from. More...
 
bool putChar (char c)
 Writes the character c to the device. More...
 
 QIODevice ()
 Constructs a QIODevice object. More...
 
 QIODevice (QObject *parent)
 Constructs a QIODevice object with the given parent. More...
 
qint64 read (char *data, qint64 maxlen)
 Reads at most maxSize bytes from the device into data, and returns the number of bytes read. More...
 
QByteArray read (qint64 maxlen)
 Reads at most maxSize bytes from the device, and returns the data read as a QByteArray. More...
 
QByteArray readAll ()
 Reads all available data from the device, and returns it as a QByteArray. More...
 
qint64 readLine (char *data, qint64 maxlen)
 This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes, stores the characters in data, and returns the number of bytes read. More...
 
QByteArray readLine (qint64 maxlen=0)
 Reads a line from the device, but no more than maxSize characters, and returns the result as a QByteArray. More...
 
virtual bool reset ()
 Seeks to the start of input for random-access devices. More...
 
virtual bool seek (qint64 pos)
 For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred. More...
 
void setTextModeEnabled (bool enabled)
 If enabled is true, this function sets the Text flag on the device; otherwise the Text flag is removed. More...
 
virtual qint64 size () const
 For open random-access devices, this function returns the size of the device. More...
 
void ungetChar (char c)
 Puts the character c back into the device, and decrements the current position unless the position is 0. More...
 
virtual bool waitForBytesWritten (int msecs)
 For buffered devices, this function waits until a payload of buffered written data has been written to the device and the bytesWritten() signal has been emitted, or until msecs milliseconds have passed. More...
 
virtual bool waitForReadyRead (int msecs)
 Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. More...
 
qint64 write (const char *data, qint64 len)
 Writes at most maxSize bytes of data from data to the device. More...
 
qint64 write (const char *data)
 Writes data from a zero-terminated string of 8-bit characters to the device. More...
 
qint64 write (const QByteArray &data)
 Writes the content of byteArray to the device. More...
 
virtual ~QIODevice ()
 The destructor is virtual, and QIODevice is an abstract base class. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

 QNetworkReply (QObject *parent=0)
 Creates a QNetworkReply object with parent parent. More...
 
 QNetworkReply (QNetworkReplyPrivate &dd, QObject *parent)
 
void setAttribute (QNetworkRequest::Attribute code, const QVariant &value)
 Sets the attribute code to have value value. More...
 
void setError (NetworkError errorCode, const QString &errorString)
 Sets the error condition to be errorCode. More...
 
void setFinished (bool)
 Sets the reply as finished. More...
 
void setHeader (QNetworkRequest::KnownHeaders header, const QVariant &value)
 Sets the known header header to be of value value. More...
 
void setOperation (QNetworkAccessManager::Operation operation)
 Sets the associated operation for this object to be operation. More...
 
void setRawHeader (const QByteArray &headerName, const QByteArray &value)
 Sets the raw header headerName to be of value value. More...
 
void setRequest (const QNetworkRequest &request)
 Sets the associated request for this object to be request. More...
 
void setUrl (const QUrl &url)
 Sets the URL being processed to be url. More...
 
virtual qint64 writeData (const char *data, qint64 len)
 
- Protected Functions inherited from QIODevice
 QIODevice (QIODevicePrivate &dd, QObject *parent=0)
 
virtual qint64 readData (char *data, qint64 maxlen)=0
 Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an error occurred. More...
 
virtual qint64 readLineData (char *data, qint64 maxlen)
 Reads up to maxSize characters into data and returns the number of characters read. More...
 
void setErrorString (const QString &errorString)
 Sets the human readable description of the last device error that occurred to str. More...
 
void setOpenMode (OpenMode openMode)
 Sets the OpenMode of the device to openMode. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

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

Since
4.4
Note
This class or function is reentrant.
Attention
Module: QtNetwork

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 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 error() or finished() signal. Use deleteLater().
See also
QNetworkRequest, QNetworkAccessManager

Definition at line 65 of file qnetworkreply.h.

Typedefs

◆ RawHeaderPair

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

Definition at line 132 of file qnetworkreply.h.

Enumerations

◆ NetworkError

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

  • NoError no 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.
  • ConnectionRefusedError the remote server refused the connection (the server is not accepting requests)
  • RemoteHostClosedError the remote server closed the connection prematurely, before the entire reply was received and processed
  • HostNotFoundError the remote host name was not found (invalid hostname)
  • TimeoutError the connection to the remote server timed out
  • OperationCanceledError the operation was canceled via calls to abort() or close() before it was finished.
  • SslHandshakeFailedError the SSL/TLS handshake failed and the encrypted channel could not be established. The sslErrors() signal should have been emitted.
  • TemporaryNetworkFailureError the 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.
  • ProxyConnectionRefusedError the connection to the proxy server was refused (the proxy server is not accepting requests)
  • ProxyConnectionClosedError the proxy server closed the connection prematurely, before the entire reply was received and processed
  • ProxyNotFoundError the proxy host name was not found (invalid proxy hostname)
  • ProxyTimeoutError the connection to the proxy timed out or the proxy did not reply in time to the request sent
  • ProxyAuthenticationRequiredError the proxy requires authentication in order to honour the request but did not accept any credentials offered (if any)
  • ContentAccessDenied the access to the remote content was denied (similar to HTTP error 401)
  • ContentOperationNotPermittedError the operation requested on the remote content is not permitted
  • ContentNotFoundError the remote content was not found at the server (similar to HTTP error 404)
  • AuthenticationRequiredError the remote server requires authentication to serve the content but the credentials provided were not accepted (if any)
  • ContentReSendError the request needed to be sent again, but this failed for example because the upload data could not be read a second time.
  • ProtocolUnknownError the Network Access API cannot honor the request because the protocol is not known
  • ProtocolInvalidOperationError the requested operation is invalid for this protocol
  • UnknownNetworkError an unknown network-related error was detected
  • UnknownProxyError an unknown proxy-related error was detected
  • UnknownContentError an unknown error related to the remote content was detected
  • ProtocolFailure a breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.)
See also
error()
Enumerator
NoError 
ConnectionRefusedError 
RemoteHostClosedError 
HostNotFoundError 
TimeoutError 
OperationCanceledError 
SslHandshakeFailedError 
TemporaryNetworkFailureError 
UnknownNetworkError 
ProxyConnectionRefusedError 
ProxyConnectionClosedError 
ProxyNotFoundError 
ProxyTimeoutError 
ProxyAuthenticationRequiredError 
UnknownProxyError 
ContentAccessDenied 
ContentOperationNotPermittedError 
ContentNotFoundError 
AuthenticationRequiredError 
ContentReSendError 
UnknownContentError 
ProtocolUnknownError 
ProtocolInvalidOperationError 
ProtocolFailure 

Definition at line 70 of file qnetworkreply.h.

70  {
71  NoError = 0,
72 
73  // network layer errors [relating to the destination server] (1-99):
82 
83  // proxy errors (101-199):
89  UnknownProxyError = 199,
90 
91  // content errors (201-299):
92  ContentAccessDenied = 201,
97  UnknownContentError = 299,
98 
99  // protocol errors
100  ProtocolUnknownError = 301,
102  ProtocolFailure = 399
103  };

Constructors and Destructors

◆ ~QNetworkReply()

QNetworkReply::~QNetworkReply ( )

Disposes of this reply and frees any resources associated with it.

If any network connections are still open, they will be closed.

See also
abort(), close()

Definition at line 380 of file qnetworkreply.cpp.

381 {
382 }

◆ QNetworkReply() [1/2]

QNetworkReply::QNetworkReply ( QObject parent = 0)
protected

Creates a QNetworkReply object with parent parent.

You cannot directly instantiate QNetworkReply objects. Use QNetworkAccessManager functions to do that.

Definition at line 360 of file qnetworkreply.cpp.

361  : QIODevice(*new QNetworkReplyPrivate, parent)
362 {
363 }
QIODevice()
Constructs a QIODevice object.
Definition: qiodevice.cpp:390

◆ QNetworkReply() [2/2]

QNetworkReply::QNetworkReply ( QNetworkReplyPrivate dd,
QObject parent 
)
protected
Warning
This function is not part of the public interface.

Definition at line 368 of file qnetworkreply.cpp.

369  : QIODevice(dd, parent)
370 {
371 }
QIODevice()
Constructs a QIODevice object.
Definition: qiodevice.cpp:390

Functions

◆ abort()

void QNetworkReply::abort ( )
pure virtual

Aborts the operation immediately and close down any network connections still open.

Uploads still in progress are also aborted.

See also
close()

Implemented in QDisabledNetworkReply, QNetworkReplyImpl, QNetworkReplyFileImpl, QNetworkReplyDataImpl, and QPatternist::QIODeviceDelegate.

◆ attribute()

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

Returns the attribute associated with the code code.

If the attribute has not been set, it returns an invalid QVariant (type QVariant::Null).

You can expect the default values listed in QNetworkRequest::Attribute to be applied to the values returned by this function.

See also
setAttribute(), QNetworkRequest::Attribute

Definition at line 607 of file qnetworkreply.cpp.

Referenced by QDeclarativeXMLHttpRequest::downloadProgress(), QDeclarativeXMLHttpRequest::error(), QDeclarativeInclude::finished(), QDeclarativeXMLHttpRequest::finished(), QDeclarativeDataLoader::networkReplyFinished(), QDeclarativePixmapReader::networkRequestDone(), and QDeclarativeFontObject::replyFinished().

608 {
609  return d_func()->attributes.value(code);
610 }

◆ close()

void QNetworkReply::close ( )
virtual

Closes this device for reading.

Unread data is discarded, but the network resources are not discarded until they are finished. In particular, if any upload is in progress, it will continue until it is done.

The finished() signal is emitted when all operations are over and the network resources are freed.

See also
abort(), finished()

Reimplemented from QIODevice.

Reimplemented in QNetworkReplyImpl, QPatternist::QIODeviceDelegate, QNetworkReplyFileImpl, and QNetworkReplyDataImpl.

Definition at line 395 of file qnetworkreply.cpp.

Referenced by QNetworkReplyDataImpl::abort(), QNetworkReplyFileImpl::abort(), QNetworkReplyImpl::abort(), QNetworkReplyDataImpl::close(), QNetworkReplyFileImpl::close(), QNetworkReplyImpl::close(), and QDeclarativePixmapReader::processJobs().

396 {
398 }
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
Definition: qiodevice.cpp:590

◆ downloadProgress

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

This signal is emitted to indicate the progress of the download part of this network request, if there's any.

If there's no download associated with this request, this signal will be emitted once with 0 as the value of both bytesReceived and bytesTotal.

The bytesReceived parameter indicates the number of bytes received, while bytesTotal indicates the total number of bytes expected to be downloaded. If the number of bytes to be downloaded is not known, bytesTotal will be -1.

The download is finished when bytesReceived is equal to bytesTotal. At that time, bytesTotal will not be -1.

Note that the values of both bytesReceived and bytesTotal may be different from size(), the total number of bytes obtained through read() or readAll(), or the value of the header(ContentLengthHeader). The reason for that is that there may be protocol overhead or the data may be compressed during the download.

See also
uploadProgress(), bytesAvailable()

◆ error() [1/2]

QNetworkReply::NetworkError QNetworkReply::error ( ) const

Returns the error that was found during the processing of this request.

If no error was found, returns NoError.

See also
setError()

Definition at line 479 of file qnetworkreply.cpp.

Referenced by QDeclarativeInclude::finished(), QDeclarativeDataLoader::networkReplyFinished(), QDeclarativePixmapReader::networkRequestDone(), QPatternist::QIODeviceDelegate::networkTimeout(), and QDeclarativeFontObject::replyFinished().

480 {
481  return d_func()->errorCode;
482 }

◆ error [2/2]

void QNetworkReply::error ( QNetworkReply::NetworkError  code)
signal

This signal is emitted when the reply detects an error in processing.

The finished() signal will probably follow, indicating that the connection is over.

The code parameter contains the code of the error that was detected. Call errorString() to obtain a textual representation of the error condition.

Note
Do not delete the object in the slot connected to this signal. Use deleteLater().
See also
error(), errorString()

◆ finished

void QNetworkReply::finished ( )
signal

This signal is emitted when the reply has finished processing.

After this signal is emitted, there will be no more updates to the reply's data or metadata.

Unless close() has been called, the reply will be still be opened for reading, so the data can be retrieved by calls to read() or readAll(). In particular, if no calls to read() were made as a result of readyRead(), a call to readAll() will retrieve the full contents in a QByteArray.

This signal is emitted in tandem with QNetworkAccessManager::finished() where that signal's reply parameter is this object.

Note
Do not delete the object in the slot connected to this signal. Use deleteLater().

You can also use isFinished() to check if a QNetworkReply has finished even before you receive the finished() signal.

See also
QNetworkAccessManager::finished(), isFinished()

Referenced by QPatternist::QIODeviceDelegate::QIODeviceDelegate(), and setFinished().

◆ hasRawHeader()

bool QNetworkReply::hasRawHeader ( const QByteArray headerName) const

Returns true if the raw header of name headerName was sent by the remote server.

See also
rawHeader()

Definition at line 544 of file qnetworkreply.cpp.

545 {
546  Q_D(const QNetworkReply);
547  return d->findRawHeader(headerName) != d->rawHeaders.constEnd();
548 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482

◆ header()

QVariant QNetworkReply::header ( QNetworkRequest::KnownHeaders  header) const

Returns the value of the known header header, if that header was sent by the remote server.

If the header was not sent, returns an invalid QVariant.

See also
rawHeader(), setHeader(), QNetworkRequest::header()

Definition at line 533 of file qnetworkreply.cpp.

534 {
535  return d_func()->cookedHeaders.value(header);
536 }
QVariant header(QNetworkRequest::KnownHeaders header) const
Returns the value of the known header header, if that header was sent by the remote server...

◆ ignoreSslErrors() [1/2]

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

If this function is called, the SSL errors given in errors will be ignored.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

Note that you can set the expected certificate in the SSL error: If, for instance, you want to issue a request to a server that uses a self-signed certificate, consider the following snippet:

QList<QSslError> expectedSslErrors;
expectedSslErrors.append(error);
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl("https://server.tld/index.html")));
reply->ignoreSslErrors(expectedSslErrors);
// here connect signals etc.

Multiple calls to this function will replace the list of errors that were passed in previous calls. You can clear the list of errors you want to ignore by calling this function with an empty list.

See also
sslConfiguration(), sslErrors(), QSslSocket::ignoreSslErrors()

Definition at line 675 of file qnetworkreply.cpp.

676 {
677  // do this cryptic trick, because we could not add a virtual method to this class later on
678  // since that breaks binary compatibility
679  int id = metaObject()->indexOfMethod("ignoreSslErrorsImplementation(QList<QSslError>)");
680  if (id != -1) {
681  QList<QSslError> copy(errors);
682  void *arr[] = { 0, &copy };
683  qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
684  }
685 }
int indexOfMethod(const char *method) const
Finds method and returns its index; otherwise returns -1.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ ignoreSslErrors [2/2]

void QNetworkReply::ignoreSslErrors ( )
virtualslot

If this function is called, SSL errors related to network connection will be ignored, including certificate validation errors.

Warning
Be sure to always let the user inspect the errors reported by the sslErrors() signal, and only call this method upon confirmation from the user that proceeding is ok. If there are unexpected errors, the reply should be aborted. Calling this method without inspecting the actual errors will most likely pose a security risk for your application. Use it with great care!

This function can be called from the slot connected to the sslErrors() signal, which indicates which errors were found.

See also
sslConfiguration(), sslErrors(), QSslSocket::ignoreSslErrors()

Reimplemented in QNetworkReplyImpl.

Definition at line 707 of file qnetworkreply.cpp.

708 {
709 }

◆ isFinished()

bool QNetworkReply::isFinished ( ) const

Returns true when the reply has finished or was aborted.

Since
4.6
See also
isRunning()

Definition at line 494 of file qnetworkreply.cpp.

Referenced by isRunning(), and QDeclarativeDataLoader::load().

495 {
496  return d_func()->isFinished;
497 }

◆ isRunning()

bool QNetworkReply::isRunning ( ) const

Returns true when the request is still processing and the reply has not finished or was aborted yet.

Since
4.6
See also
isFinished()

Definition at line 510 of file qnetworkreply.cpp.

Referenced by QDeclarativePixmapReader::processJobs().

511 {
512  return !isFinished();
513 }
bool isFinished() const
Returns true when the reply has finished or was aborted.

◆ isSequential()

bool QNetworkReply::isSequential ( ) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QIODevice.

Reimplemented in QPatternist::QIODeviceDelegate, QNetworkReplyFileImpl, and QNetworkReplyDataImpl.

Definition at line 403 of file qnetworkreply.cpp.

404 {
405  return true;
406 }

◆ manager()

QNetworkAccessManager * QNetworkReply::manager ( ) const

Returns the QNetworkAccessManager that was used to create this QNetworkReply object.

Initially, it is also the parent object.

Definition at line 446 of file qnetworkreply.cpp.

Referenced by QNetworkReplyImplPrivate::migrateBackend(), QDeclarativeFontObject::replyFinished(), and QNetworkReplyPrivate::setManager().

447 {
448  return d_func()->manager;
449 }

◆ metaDataChanged

void QNetworkReply::metaDataChanged ( )
signal

This signal is emitted whenever the metadata in this reply changes.

Warning
This function is not part of the public interface. FIXME: Update name?

metadata is any information that is not the content (data) itself, including the network headers. In the majority of cases, the metadata will be known fully by the time the first byte of data is received. However, it is possible to receive updates of headers or other metadata during the processing of the data.

See also
header(), rawHeaderList(), rawHeader(), hasRawHeader()

◆ operation()

QNetworkAccessManager::Operation QNetworkReply::operation ( ) const

Returns the operation that was posted for this reply.

See also
setOperation()

Definition at line 468 of file qnetworkreply.cpp.

Referenced by QNetworkReplyImplPrivate::migrateBackend(), and setOperation().

469 {
470  return d_func()->operation;
471 }

◆ rawHeader()

QByteArray QNetworkReply::rawHeader ( const QByteArray headerName) const

Returns the raw contents of the header headerName as sent by the remote server.

If there is no such header, returns an empty byte array, which may be indistinguishable from an empty header. Use hasRawHeader() to verify if the server sent such header field.

See also
setRawHeader(), hasRawHeader(), header()

Definition at line 559 of file qnetworkreply.cpp.

Referenced by QDeclarativeXMLHttpRequest::fillHeadersList().

560 {
561  Q_D(const QNetworkReply);
563  d->findRawHeader(headerName);
564  if (it != d->rawHeaders.constEnd())
565  return it->second;
566  return QByteArray();
567 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_D(Class)
Definition: qglobal.h:2482
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279

◆ rawHeaderList()

QList< QByteArray > QNetworkReply::rawHeaderList ( ) const

Returns a list of headers fields that were sent by the remote server, in the order that they were sent.

Duplicate headers are merged together and take place of the latter duplicate.

Definition at line 592 of file qnetworkreply.cpp.

Referenced by QDeclarativeXMLHttpRequest::fillHeadersList().

593 {
594  return d_func()->rawHeadersKeys();
595 }

◆ rawHeaderPairs()

const QList< QNetworkReply::RawHeaderPair > & QNetworkReply::rawHeaderPairs ( ) const

Returns a list of raw header pairs.

Definition at line 581 of file qnetworkreply.cpp.

582 {
583  Q_D(const QNetworkReply);
584  return d->rawHeaders;
585 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482

◆ readBufferSize()

qint64 QNetworkReply::readBufferSize ( ) const

Returns the size of the read buffer, in bytes.

See also
setReadBufferSize()

Definition at line 413 of file qnetworkreply.cpp.

Referenced by QNetworkReplyImpl::readData().

414 {
415  return d_func()->readBufferMaxSize;
416 }

◆ request()

QNetworkRequest QNetworkReply::request ( ) const

Returns the request that was posted for this reply.

In special, note that the URL for the request may be different than that of the reply.

See also
QNetworkRequest::url(), url(), setRequest()

Definition at line 458 of file qnetworkreply.cpp.

Referenced by QNetworkReplyImplPrivate::migrateBackend(), and setRequest().

459 {
460  return d_func()->request;
461 }

◆ setAttribute()

void QNetworkReply::setAttribute ( QNetworkRequest::Attribute  code,
const QVariant value 
)
protected

Sets the attribute code to have value value.

If code was previously set, it will be overridden. If value is an invalid QVariant, the attribute will be unset.

See also
attribute(), QNetworkRequest::setAttribute()

Definition at line 833 of file qnetworkreply.cpp.

834 {
836  if (value.isValid())
837  d->attributes.insert(code, value);
838  else
839  d->attributes.remove(code);
840 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485

◆ setError()

void QNetworkReply::setError ( NetworkError  errorCode,
const QString errorString 
)
protected

Sets the error condition to be errorCode.

The human-readable message is set with errorString.

Calling setError() does not emit the error(QNetworkReply::NetworkError) signal.

See also
error(), errorString()

Definition at line 758 of file qnetworkreply.cpp.

Referenced by QDisabledNetworkReply::QDisabledNetworkReply(), QNetworkReplyDataImpl::QNetworkReplyDataImpl(), and QNetworkReplyFileImpl::QNetworkReplyFileImpl().

759 {
761  d->errorCode = errorCode;
762  setErrorString(errorString); // in QIODevice
763 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482
void setErrorString(const QString &errorString)
Sets the human readable description of the last device error that occurred to str.
Definition: qiodevice.cpp:1660

◆ setFinished()

void QNetworkReply::setFinished ( bool  finished)
protected

Sets the reply as finished.

Since
4.8

After having this set the replies data must not change.

See also
isFinished()

Definition at line 776 of file qnetworkreply.cpp.

Referenced by QNetworkReplyDataImpl::QNetworkReplyDataImpl(), and QNetworkReplyFileImpl::QNetworkReplyFileImpl().

777 {
779  d->isFinished = finished;
780 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482
void finished()
This signal is emitted when the reply has finished processing.

◆ setHeader()

void QNetworkReply::setHeader ( QNetworkRequest::KnownHeaders  header,
const QVariant value 
)
protected

Sets the known header header to be of value value.

The corresponding raw form of the header will be set as well.

See also
header(), setRawHeader(), QNetworkRequest::setHeader()

Definition at line 803 of file qnetworkreply.cpp.

Referenced by QNetworkReplyDataImpl::QNetworkReplyDataImpl(), and QNetworkReplyFileImpl::QNetworkReplyFileImpl().

804 {
806  d->setCookedHeader(header, value);
807 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482
QVariant header(QNetworkRequest::KnownHeaders header) const
Returns the value of the known header header, if that header was sent by the remote server...

◆ setOperation()

void QNetworkReply::setOperation ( QNetworkAccessManager::Operation  operation)
protected

Sets the associated operation for this object to be operation.

This value will be returned by operation().

Note: the operation should be set when this object is created and not changed again.

See also
operation(), setRequest()

Definition at line 728 of file qnetworkreply.cpp.

Referenced by QDisabledNetworkReply::QDisabledNetworkReply(), QNetworkReplyDataImpl::QNetworkReplyDataImpl(), and QNetworkReplyFileImpl::QNetworkReplyFileImpl().

729 {
731  d->operation = operation;
732 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482
QNetworkAccessManager::Operation operation() const
Returns the operation that was posted for this reply.

◆ setRawHeader()

void QNetworkReply::setRawHeader ( const QByteArray headerName,
const QByteArray value 
)
protected

Sets the raw header headerName to be of value value.

If headerName was previously set, it is overridden. Multiple HTTP headers of the same name are functionally equivalent to one single header with the values concatenated, separated by commas.

If headerName matches a known header, the value value will be parsed and the corresponding parsed form will also be set.

See also
rawHeader(), header(), setHeader(), QNetworkRequest::setRawHeader()

Definition at line 820 of file qnetworkreply.cpp.

821 {
823  d->setRawHeader(headerName, value);
824 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setReadBufferSize()

void QNetworkReply::setReadBufferSize ( qint64  size)
virtual

Sets the size of the read buffer to be size bytes.

The read buffer is the buffer that holds data that is being downloaded off the network, before it is read with QIODevice::read(). Setting the buffer size to 0 will make the buffer unlimited in size.

QNetworkReply will try to stop reading from the network once this buffer is full (i.e., bytesAvailable() returns size or more), thus causing the download to throttle down as well. If the buffer is not limited in size, QNetworkReply will try to download as fast as possible from the network.

Unlike QAbstractSocket::setReadBufferSize(), QNetworkReply cannot guarantee precision in the read buffer size. That is, bytesAvailable() can return more than size.

See also
readBufferSize()

Reimplemented in QNetworkReplyImpl.

Definition at line 436 of file qnetworkreply.cpp.

Referenced by QNetworkReplyImpl::setReadBufferSize().

437 {
439  d->readBufferMaxSize = size;
440 }
double d
Definition: qnumeric_p.h:62
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setRequest()

void QNetworkReply::setRequest ( const QNetworkRequest request)
protected

Sets the associated request for this object to be request.

This value will be returned by request().

Note: the request should be set when this object is created and not changed again.

See also
request(), setOperation()

Definition at line 743 of file qnetworkreply.cpp.

Referenced by QDisabledNetworkReply::QDisabledNetworkReply(), QNetworkReplyDataImpl::QNetworkReplyDataImpl(), and QNetworkReplyFileImpl::QNetworkReplyFileImpl().

744 {
746  d->request = request;
747 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482
QNetworkRequest request() const
Returns the request that was posted for this reply.

◆ setSslConfiguration()

void QNetworkReply::setSslConfiguration ( const QSslConfiguration configuration)

Sets the SSL configuration for the network connection associated with this request, if possible, to be that of config.

Definition at line 639 of file qnetworkreply.cpp.

Referenced by QNetworkAccessManager::createRequest().

640 {
641  if (config.isNull())
642  return;
643 
644  int id = metaObject()->indexOfMethod("setSslConfigurationImplementation(QSslConfiguration)");
645  if (id != -1) {
646  QSslConfiguration copy(config);
647  void *arr[] = { 0, &copy };
648  qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
649  }
650 }
int indexOfMethod(const char *method) const
Finds method and returns its index; otherwise returns -1.
The QSslConfiguration class holds the configuration and state of an SSL connection.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ setUrl()

void QNetworkReply::setUrl ( const QUrl url)
protected

Sets the URL being processed to be url.

Normally, the URL matches that of the request that was posted, but for a variety of reasons it can be different (for example, a file path being made absolute or canonical).

See also
url(), request(), QNetworkRequest::url()

Definition at line 791 of file qnetworkreply.cpp.

Referenced by QDisabledNetworkReply::QDisabledNetworkReply(), QNetworkReplyDataImpl::QNetworkReplyDataImpl(), and QNetworkReplyFileImpl::QNetworkReplyFileImpl().

792 {
794  d->url = url;
795 }
double d
Definition: qnumeric_p.h:62
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_D(Class)
Definition: qglobal.h:2482
QUrl url() const
Returns the URL of the content downloaded or uploaded.

◆ sslConfiguration()

QSslConfiguration QNetworkReply::sslConfiguration ( ) const

Returns the SSL configuration and state associated with this reply, if SSL was used.

It will contain the remote server's certificate, its certificate chain leading to the Certificate Authority as well as the encryption ciphers in use.

The peer's certificate and its certificate chain will be known by the time sslErrors() is emitted, if it's emitted.

Definition at line 622 of file qnetworkreply.cpp.

623 {
624  QSslConfiguration config;
625 
626  // determine if we support this extension
627  int id = metaObject()->indexOfMethod("sslConfigurationImplementation()");
628  if (id != -1) {
629  void *arr[] = { &config, 0 };
630  const_cast<QNetworkReply *>(this)->qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
631  }
632  return config;
633 }
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
int indexOfMethod(const char *method) const
Finds method and returns its index; otherwise returns -1.
The QSslConfiguration class holds the configuration and state of an SSL connection.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ sslErrors

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

This signal is emitted if the SSL/TLS session encountered errors during the set up, including certificate verification errors.

The errors parameter contains the list of errors.

To indicate that the errors are not fatal and that the connection should proceed, the ignoreSslErrors() function should be called from the slot connected to this signal. If it is not called, the SSL session will be torn down before any data is exchanged (including the URL).

This signal can be used to display an error message to the user indicating that security may be compromised and display the SSL settings (see sslConfiguration() to obtain it). If the user decides to proceed after analyzing the remote certificate, the slot should call ignoreSslErrors().

See also
QSslSocket::sslErrors(), QNetworkAccessManager::sslErrors(), sslConfiguration(), ignoreSslErrors()

◆ uploadProgress

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

This signal is emitted to indicate the progress of the upload part of this network request, if there's any.

If there's no upload associated with this request, this signal will not be emitted.

The bytesSent parameter indicates the number of bytes uploaded, while bytesTotal indicates the total number of bytes to be uploaded. If the number of bytes to be uploaded could not be determined, bytesTotal will be -1.

The upload is finished when bytesSent is equal to bytesTotal. At that time, bytesTotal will not be -1.

See also
downloadProgress()

◆ url()

QUrl QNetworkReply::url ( ) const

Returns the URL of the content downloaded or uploaded.

Note that the URL may be different from that of the original request.

See also
request(), setUrl(), QNetworkRequest::url()

Definition at line 521 of file qnetworkreply.cpp.

Referenced by QDeclarativeXMLHttpRequest::finished(), QDeclarativeDataLoader::networkReplyFinished(), QDeclarativePixmapReader::networkRequestDone(), QNetworkReplyDataImpl::QNetworkReplyDataImpl(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QDeclarativeFontObject::replyFinished(), setUrl(), and QNetworkReplyImpl::~QNetworkReplyImpl().

522 {
523  return d_func()->url;
524 }

◆ writeData()

qint64 QNetworkReply::writeData ( const char *  data,
qint64  len 
)
protectedvirtual
Warning
This function is not part of the public interface.

Implements QIODevice.

Definition at line 714 of file qnetworkreply.cpp.

715 {
716  return -1; // you can't write
717 }

The documentation for this class was generated from the following files: