Qt 4.8
Public Types | Signals | Public Functions | Protected Functions | Properties | Friends | List of all members
QNetworkAccessManager Class Reference

The QNetworkAccessManager class allows the application to send network requests and receive replies. More...

#include <qnetworkaccessmanager.h>

Inheritance diagram for QNetworkAccessManager:
QObject QPatternist::URILoader

Public Types

enum  NetworkAccessibility { UnknownAccessibility = -1, NotAccessible = 0, Accessible = 1 }
 Indicates whether the network is accessible via this network access manager. More...
 
enum  Operation {
  HeadOperation = 1, GetOperation, PutOperation, PostOperation,
  DeleteOperation, CustomOperation, UnknownOperation = 0
}
 Indicates the operation this reply is processing. More...
 

Signals

void authenticationRequired (QNetworkReply *reply, QAuthenticator *authenticator)
 This signal is emitted whenever a final server requests authentication before it delivers the requested contents. More...
 
void finished (QNetworkReply *reply)
 This signal is emitted whenever a pending network reply is finished. More...
 
void networkAccessibleChanged (QNetworkAccessManager::NetworkAccessibility accessible)
 This signal is emitted when the value of the networkAccessible property changes. More...
 
void networkSessionConnected ()
 This signal is emitted when the status of the network session changes into a usable (Connected) state. More...
 
void proxyAuthenticationRequired (const QNetworkProxy &proxy, QAuthenticator *authenticator)
 This signal is emitted whenever a proxy requests authentication and QNetworkAccessManager cannot find a valid, cached credential. More...
 
void sslErrors (QNetworkReply *reply, const QList< QSslError > &errors)
 This signal is emitted if the SSL/TLS session encountered errors during the set up, including certificate verification errors. 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

QNetworkConfiguration activeConfiguration () const
 Returns the current active network configuration. More...
 
QAbstractNetworkCachecache () const
 Returns the cache that is used to store data obtained from the network. More...
 
QNetworkConfiguration configuration () const
 Returns the network configuration that will be used to create the QNetworkSession{network session} which will be used when processing network requests. More...
 
QNetworkCookieJarcookieJar () const
 Returns the QNetworkCookieJar that is used to store cookies obtained from the network as well as cookies that are about to be sent. More...
 
QNetworkReplydeleteResource (const QNetworkRequest &request)
 Sends a request to delete the resource identified by the URL of request. More...
 
QNetworkReplyget (const QNetworkRequest &request)
 Posts a request to obtain the contents of the target request and returns a new QNetworkReply object opened for reading which emits the readyRead() signal whenever new data arrives. More...
 
QNetworkReplyhead (const QNetworkRequest &request)
 Posts a request to obtain the network headers for request and returns a new QNetworkReply object which will contain such headers. More...
 
NetworkAccessibility networkAccessible () const
 
QNetworkReplypost (const QNetworkRequest &request, QIODevice *data)
 Sends an HTTP POST request to the destination specified by request and returns a new QNetworkReply object opened for reading that will contain the reply sent by the server. More...
 
QNetworkReplypost (const QNetworkRequest &request, const QByteArray &data)
 Sends the contents of the data byte array to the destination specified by request. More...
 
QNetworkReplypost (const QNetworkRequest &request, QHttpMultiPart *multiPart)
 Sends the contents of the multiPart message to the destination specified by request. More...
 
QNetworkProxy proxy () const
 Returns the QNetworkProxy that the requests sent using this QNetworkAccessManager object will use. More...
 
QNetworkProxyFactoryproxyFactory () const
 
QNetworkReplyput (const QNetworkRequest &request, QIODevice *data)
 Uploads the contents of data to the destination request and returnes a new QNetworkReply object that will be open for reply. More...
 
QNetworkReplyput (const QNetworkRequest &request, const QByteArray &data)
 Sends the contents of the data byte array to the destination specified by request. More...
 
QNetworkReplyput (const QNetworkRequest &request, QHttpMultiPart *multiPart)
 Sends the contents of the multiPart message to the destination specified by request. More...
 
 QNetworkAccessManager (QObject *parent=0)
 Constructs a QNetworkAccessManager object that is the center of the Network Access API and sets parent as the parent object. More...
 
QNetworkReplysendCustomRequest (const QNetworkRequest &request, const QByteArray &verb, QIODevice *data=0)
 Sends a custom request to the server identified by the URL of request. More...
 
void setCache (QAbstractNetworkCache *cache)
 Sets the manager's network cache to be the cache specified. More...
 
void setConfiguration (const QNetworkConfiguration &config)
 Sets the network configuration that will be used when creating the QNetworkSession{network session} to config. More...
 
void setCookieJar (QNetworkCookieJar *cookieJar)
 Sets the manager's cookie jar to be the cookieJar specified. More...
 
void setNetworkAccessible (NetworkAccessibility accessible)
 Overrides the reported network accessibility. More...
 
void setProxy (const QNetworkProxy &proxy)
 Sets the proxy to be used in future requests to be proxy. More...
 
void setProxyFactory (QNetworkProxyFactory *factory)
 Sets the proxy factory for this class to be factory. More...
 
 ~QNetworkAccessManager ()
 Destroys the QNetworkAccessManager object and frees up any resources. 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

virtual QNetworkReplycreateRequest (Operation op, const QNetworkRequest &request, QIODevice *outgoingData=0)
 Returns a new QNetworkReply object to handle the operation op and request req. 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...
 

Properties

NetworkAccessibility networkAccessible
 whether the network is currently accessible via this network access manager. More...
 

Friends

class QNetworkAccessHttpBackend
 
class QNetworkReplyImplPrivate
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- 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 QNetworkAccessManager class allows the application to send network requests and receive replies.

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

The Network Access API is constructed around one QNetworkAccessManager object, which holds the common configuration and settings for the requests it sends. It contains the proxy and cache configuration, as well as the signals related to such issues, and reply signals that can be used to monitor the progress of a network operation. One QNetworkAccessManager should be enough for the whole Qt application.

Once a QNetworkAccessManager object has been created, the application can use it to send requests over the network. A group of standard functions are supplied that take a request and optional data, and each return a QNetworkReply object. The returned object is used to obtain any data returned in response to the corresponding request.

A simple download off the network could be accomplished with:

this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));

QNetworkAccessManager has an asynchronous API. When the replyFinished slot above is called, the parameter it takes is the QNetworkReply object containing the downloaded data as well as meta-data (headers, etc.).

Note
After the request has finished, it is the responsibility of the user to delete the QNetworkReply object at an appropriate time. Do not directly delete it inside the slot connected to finished(). You can use the deleteLater() function.
QNetworkAccessManager queues the requests it receives. The number of requests executed in parallel is dependent on the protocol. Currently, for the HTTP protocol on desktop platforms, 6 requests are executed in parallel for one host/port combination.

A more involved example, assuming the manager is already existent, can be:

request.setUrl(QUrl("http://qt.nokia.com"));
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
QNetworkReply *reply = manager->get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
this, SLOT(slotError(QNetworkReply::NetworkError)));
this, SLOT(slotSslErrors(QList<QSslError>)));

Network and Roaming support

With the addition of the Bearer Management API to Qt 4.7 QNetworkAccessManager gained the ability to manage network connections. QNetworkAccessManager can start the network interface if the device is offline and terminates the interface if the current process is the last one to use the uplink. Note that some platform utilize grace periods from when the last application stops using a uplink until the system actually terminates the connectivity link. Roaming is equally transparent. Any queued/pending network requests are automatically transferred to new access point.

Clients wanting to utilize this feature should not require any changes. In fact it is likely that existing platform specific connection code can simply be removed from the application.

Note
The network and roaming support in QNetworkAccessManager is conditional upon the platform supporting connection management. The QNetworkConfigurationManager::NetworkSessionRequired can be used to detect whether QNetworkAccessManager utilizes this feature. Currently only Meego/Harmattan and Symbian platforms provide connection management support.
This feature cannot be used in combination with the Bearer Management API as provided by QtMobility. Applications have to migrate to the Qt version of Bearer Management.

Symbian Platform Security Requirements

On Symbian, processes which use this class must have the NetworkServices platform security capability. If the client process lacks this capability, operations will result in a panic.

Platform security capabilities are added via the TARGET.CAPABILITY qmake variable.

See also
QNetworkRequest, QNetworkReply, QNetworkProxy

Definition at line 72 of file qnetworkaccessmanager.h.

Enumerations

◆ NetworkAccessibility

Indicates whether the network is accessible via this network access manager.

  • UnknownAccessibility The network accessibility cannot be determined.
  • NotAccessible The network is not currently accessible, either because there is currently no network coverage or network access has been explicitly disabled by a call to setNetworkAccessible().
  • Accessible The network is accessible.
See also
networkAccessible
Enumerator
UnknownAccessibility 
NotAccessible 
Accessible 

Definition at line 93 of file qnetworkaccessmanager.h.

◆ Operation

Indicates the operation this reply is processing.

  • HeadOperation retrieve headers operation (created with head())
  • GetOperation retrieve headers and download contents (created with get())
  • PutOperation upload contents operation (created with put())
  • PostOperation send the contents of an HTML form for processing via HTTP POST (created with post())
  • CustomOperation custom operation (created with sendCustomRequest())
    Since
    4.7
  • UnknownOperation
See also
QNetworkReply::operation()
Enumerator
HeadOperation 
GetOperation 
PutOperation 
PostOperation 
DeleteOperation 
CustomOperation 
UnknownOperation 

Definition at line 81 of file qnetworkaccessmanager.h.

Constructors and Destructors

◆ QNetworkAccessManager()

QNetworkAccessManager::QNetworkAccessManager ( QObject parent = 0)
explicit

Constructs a QNetworkAccessManager object that is the center of the Network Access API and sets parent as the parent object.

Definition at line 375 of file qnetworkaccessmanager.cpp.

376  : QObject(*new QNetworkAccessManagerPrivate, parent)
377 {
379 
380  qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
381 }
static void ensureInitialized()
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QNetworkAccessManager()

QNetworkAccessManager::~QNetworkAccessManager ( )

Destroys the QNetworkAccessManager object and frees up any resources.

Note that QNetworkReply objects that are returned from this class have this object set as their parents, which means that they will be deleted along with it if you don't call QObject::setParent() on them.

Definition at line 390 of file qnetworkaccessmanager.cpp.

391 {
392 #ifndef QT_NO_NETWORKPROXY
393  delete d_func()->proxyFactory;
394 #endif
395 
396  // Delete the QNetworkReply children first.
397  // Else a QAbstractNetworkCache might get deleted in ~QObject
398  // before a QNetworkReply that accesses the QAbstractNetworkCache
399  // object in its destructor.
400  qDeleteAll(findChildren<QNetworkReply *>());
401  // The other children will be deleted in this ~QObject
402  // FIXME instead of this "hack" make the QNetworkReplyImpl
403  // properly watch the cache deletion, e.g. via a QWeakPointer.
404 }
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Functions

◆ activeConfiguration()

QNetworkConfiguration QNetworkAccessManager::activeConfiguration ( ) const

Returns the current active network configuration.

Since
4.7

If the network configuration returned by configuration() is of type QNetworkConfiguration::ServiceNetwork this function will return the current active child network configuration of that configuration. Otherwise returns the same network configuration as configuration().

Use this function to return the actual network configuration currently in use by the network session.

See also
configuration()

Definition at line 848 of file qnetworkaccessmanager.cpp.

849 {
850  Q_D(const QNetworkAccessManager);
851 
852  QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
853  if (networkSession) {
855 
856  return manager.configurationFromIdentifier(
857  networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString());
858  } else {
859  return QNetworkConfiguration();
860  }
861 }
double d
Definition: qnumeric_p.h:62
The QNetworkConfigurationManager class manages the network configurations provided by the system...
#define Q_D(Class)
Definition: qglobal.h:2482
The QNetworkConfiguration class provides an abstraction of one or more access point configurations...
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QNetworkAccessManager class allows the application to send network requests and receive replies...
QNetworkConfiguration configurationFromIdentifier(const QString &identifier) const
Returns the QNetworkConfiguration for identifier; otherwise returns an invalid QNetworkConfiguration...

◆ authenticationRequired

void QNetworkAccessManager::authenticationRequired ( QNetworkReply reply,
QAuthenticator authenticator 
)
signal

This signal is emitted whenever a final server requests authentication before it delivers the requested contents.

The slot connected to this signal should fill the credentials for the contents (which can be determined by inspecting the reply object) in the authenticator object.

QNetworkAccessManager will cache the credentials internally and will send the same values if the server requires authentication again, without emitting the authenticationRequired() signal. If it rejects the credentials, this signal will be emitted again.

Note
It is not possible to use a QueuedConnection to connect to this signal, as the connection will fail if the authenticator has not been filled in with new information when the signal returns.
See also
proxyAuthenticationRequired()

◆ cache()

QAbstractNetworkCache * QNetworkAccessManager::cache ( ) const

Returns the cache that is used to store data obtained from the network.

Since
4.5
See also
setCache()

Definition at line 509 of file qnetworkaccessmanager.cpp.

Referenced by setCache().

510 {
511  Q_D(const QNetworkAccessManager);
512  return d->networkCache;
513 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QNetworkAccessManager class allows the application to send network requests and receive replies...

◆ configuration()

QNetworkConfiguration QNetworkAccessManager::configuration ( ) const

Returns the network configuration that will be used to create the QNetworkSession{network session} which will be used when processing network requests.

Since
4.7
See also
setConfiguration(), activeConfiguration()

Definition at line 819 of file qnetworkaccessmanager.cpp.

820 {
821  Q_D(const QNetworkAccessManager);
822 
823  QSharedPointer<QNetworkSession> session(d->getNetworkSession());
824  if (session)
825  return session->configuration();
826  else
827  return QNetworkConfiguration();
828 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QNetworkConfiguration configuration() const
Returns the QNetworkConfiguration that this network session object is based on.
The QNetworkConfiguration class provides an abstraction of one or more access point configurations...
The QNetworkAccessManager class allows the application to send network requests and receive replies...

◆ cookieJar()

QNetworkCookieJar * QNetworkAccessManager::cookieJar ( ) const

Returns the QNetworkCookieJar that is used to store cookies obtained from the network as well as cookies that are about to be sent.

See also
setCookieJar()

Definition at line 552 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkReplyImplPrivate::metaDataChanged().

553 {
554  Q_D(const QNetworkAccessManager);
555  if (!d->cookieJar)
556  d->createCookieJar();
557  return d->cookieJar;
558 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QNetworkAccessManager class allows the application to send network requests and receive replies...

◆ createRequest()

QNetworkReply * QNetworkAccessManager::createRequest ( QNetworkAccessManager::Operation  op,
const QNetworkRequest req,
QIODevice outgoingData = 0 
)
protectedvirtual

Returns a new QNetworkReply object to handle the operation op and request req.

The device outgoingData is always 0 for Get and Head requests, but is the value passed to post() and put() in those operations (the QByteArray variants will pass a QBuffer object).

The default implementation calls QNetworkCookieJar::cookiesForUrl() on the cookie jar set with setCookieJar() to obtain the cookies to be sent to the remote server.

The returned object must be in an open state.

Reimplemented in QPatternist::URILoader.

Definition at line 962 of file qnetworkaccessmanager.cpp.

Referenced by QPatternist::URILoader::createRequest(), deleteResource(), get(), head(), post(), put(), and sendCustomRequest().

965 {
967 
968  bool isLocalFile = req.url().isLocalFile();
969  QString scheme = req.url().scheme().toLower();
970 
971  // fast path for GET on file:// URLs
972  // The QNetworkAccessFileBackend will right now only be used for PUT
974  && (isLocalFile || scheme == QLatin1String("qrc"))) {
975  return new QNetworkReplyFileImpl(this, req, op);
976  }
977 
979  && scheme == QLatin1String("data")) {
980  return new QNetworkReplyDataImpl(this, req, op);
981  }
982 
983  // A request with QNetworkRequest::AlwaysCache does not need any bearer management
988  if (mode == QNetworkRequest::AlwaysCache
991  // FIXME Implement a QNetworkReplyCacheImpl instead, see QTBUG-15106
992  QNetworkReplyImpl *reply = new QNetworkReplyImpl(this);
993  QNetworkReplyImplPrivate *priv = reply->d_func();
994  priv->manager = this;
995  priv->backend = new QNetworkAccessCacheBackend();
996  priv->backend->manager = this->d_func();
997  priv->backend->setParent(reply);
998  priv->backend->reply = priv;
999  priv->setup(op, req, outgoingData);
1000  return reply;
1001  }
1002 
1003 #ifndef QT_NO_BEARERMANAGEMENT
1004  // Return a disabled network reply if network access is disabled.
1005  // Except if the scheme is empty or file://.
1006  if (!d->networkAccessible && !isLocalFile) {
1007  return new QDisabledNetworkReply(this, req, op);
1008  }
1009 
1010  if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.isEmpty())) {
1012  if (!d->networkConfiguration.isEmpty()) {
1013  d->createSession(manager.configurationFromIdentifier(d->networkConfiguration));
1014  } else {
1016  d->createSession(manager.defaultConfiguration());
1017  else
1018  d->initializeSession = false;
1019  }
1020  }
1021 #endif
1022 
1023  QNetworkRequest request = req;
1025  outgoingData && !outgoingData->isSequential()) {
1026  // request has no Content-Length
1027  // but the data that is outgoing is random-access
1028  request.setHeader(QNetworkRequest::ContentLengthHeader, outgoingData->size());
1029  }
1030 
1031  if (static_cast<QNetworkRequest::LoadControl>
1034  if (d->cookieJar) {
1035  QList<QNetworkCookie> cookies = d->cookieJar->cookiesForUrl(request.url());
1036  if (!cookies.isEmpty())
1038  }
1039  }
1040 
1041  // first step: create the reply
1042  QUrl url = request.url();
1043  QNetworkReplyImpl *reply = new QNetworkReplyImpl(this);
1044 #ifndef QT_NO_BEARERMANAGEMENT
1045  if (!isLocalFile) {
1047  reply, SLOT(_q_networkSessionConnected()));
1048  }
1049 #endif
1050  QNetworkReplyImplPrivate *priv = reply->d_func();
1051  priv->manager = this;
1052 
1053  // second step: fetch cached credentials
1054  // This is not done for the time being, we should use signal emissions to request
1055  // the credentials from cache.
1056 
1057  // third step: find a backend
1058  priv->backend = d->findBackend(op, request);
1059 
1060  if (priv->backend) {
1061  priv->backend->setParent(reply);
1062  priv->backend->reply = priv;
1063  }
1064 
1065 #ifndef QT_NO_OPENSSL
1066  reply->setSslConfiguration(request.sslConfiguration());
1067 #endif
1068 
1069  // fourth step: setup the reply
1070  priv->setup(op, request, outgoingData);
1071 
1072  return reply;
1073 }
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
QSslConfiguration sslConfiguration() const
Returns this network request&#39;s SSL configuration.
void networkSessionConnected()
This signal is emitted when the status of the network session changes into a usable (Connected) state...
QPointer< QNetworkAccessManager > manager
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
#define SLOT(a)
Definition: qobjectdefs.h:226
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QNetworkAccessBackend * backend
The QNetworkConfigurationManager class manages the network configurations provided by the system...
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QNetworkConfigurationManager::Capabilities capabilities() const
Returns the capabilities supported by the current platform.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QUrl url() const
Returns the URL this network request is referring to.
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
QNetworkAccessManagerPrivate * manager
bool isLocalFile() const
Returns true if this URL is pointing to a local file path.
Definition: qurl.cpp:6453
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QNetworkReplyImplPrivate * reply
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
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 rece...
Definition: qobject.cpp:2580
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
void setHeader(KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers...
The QNetworkAccessManager class allows the application to send network requests and receive replies...
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
Definition: qiodevice.cpp:454
void setSslConfiguration(const QSslConfiguration &configuration)
Sets the SSL configuration for the network connection associated with this request, if possible, to be that of config.
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
QNetworkConfiguration defaultConfiguration() const
Returns the default configuration to be used.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
static const QMetaObjectPrivate * priv(const uint *data)
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QNetworkConfiguration configurationFromIdentifier(const QString &identifier) const
Returns the QNetworkConfiguration for identifier; otherwise returns an invalid QNetworkConfiguration...
CacheLoadControl
Controls the caching mechanism of QNetworkAccessManager.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485

◆ deleteResource()

QNetworkReply * QNetworkAccessManager::deleteResource ( const QNetworkRequest request)

Sends a request to delete the resource identified by the URL of request.

Since
4.6
Note
This feature is currently available for HTTP only, performing an HTTP DELETE request.
See also
get(), post(), put(), sendCustomRequest()

Definition at line 770 of file qnetworkaccessmanager.cpp.

Referenced by QDeclarativeXMLHttpRequest::requestFromUrl().

771 {
772  return d_func()->postProcess(createRequest(QNetworkAccessManager::DeleteOperation, request));
773 }
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData=0)
Returns a new QNetworkReply object to handle the operation op and request req.

◆ finished

void QNetworkAccessManager::finished ( QNetworkReply reply)
signal

This signal is emitted whenever a pending network reply is finished.

The reply parameter will contain a pointer to the reply that has just finished. This signal is emitted in tandem with the QNetworkReply::finished() signal.

See QNetworkReply::finished() for information on the status that the object will be in.

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

Referenced by QNetworkAccessManagerPrivate::postProcess().

◆ get()

QNetworkReply * QNetworkAccessManager::get ( const QNetworkRequest request)

Posts a request to obtain the contents of the target request and returns a new QNetworkReply object opened for reading which emits the readyRead() signal whenever new data arrives.

The contents as well as associated headers will be downloaded.

See also
post(), put(), deleteResource(), sendCustomRequest()

Definition at line 623 of file qnetworkaccessmanager.cpp.

Referenced by QDeclarativeFontObject::download(), QDeclarativeInclude::finished(), QDeclarativeBorderImage::load(), QDeclarativeAnimatedImage::load(), QPatternist::AccelTreeResourceLoader::load(), QDeclarativeDataLoader::load(), QDeclarativeDataLoader::networkReplyFinished(), QDeclarativePixmapReader::networkRequestDone(), QDeclarativeInclude::QDeclarativeInclude(), QDeclarativeXmlListModel::reload(), and QDeclarativeXMLHttpRequest::requestFromUrl().

624 {
625  return d_func()->postProcess(createRequest(QNetworkAccessManager::GetOperation, request));
626 }
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData=0)
Returns a new QNetworkReply object to handle the operation op and request req.

◆ head()

QNetworkReply * QNetworkAccessManager::head ( const QNetworkRequest request)

Posts a request to obtain the network headers for request and returns a new QNetworkReply object which will contain such headers.

The function is named after the HTTP request associated (HEAD).

Definition at line 608 of file qnetworkaccessmanager.cpp.

Referenced by QDeclarativeXMLHttpRequest::requestFromUrl().

609 {
610  return d_func()->postProcess(createRequest(QNetworkAccessManager::HeadOperation, request));
611 }
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData=0)
Returns a new QNetworkReply object to handle the operation op and request req.

◆ networkAccessible()

NetworkAccessibility QNetworkAccessManager::networkAccessible ( ) const

◆ networkAccessibleChanged

void QNetworkAccessManager::networkAccessibleChanged ( QNetworkAccessManager::NetworkAccessibility  accessible)
signal

This signal is emitted when the value of the networkAccessible property changes.

accessible is the new network accessibility.

Referenced by setNetworkAccessible().

◆ networkSessionConnected

void QNetworkAccessManager::networkSessionConnected ( )
signal

This signal is emitted when the status of the network session changes into a usable (Connected) state.

Since
4.7
Warning
This function is not part of the public interface.

It is used to signal to QNetworkReplys to start or migrate their network operation once the network session has been opened or finished roaming.

Referenced by QNetworkAccessManagerPrivate::_q_networkSessionClosed(), createRequest(), and QNetworkAccessManagerPrivate::createSession().

◆ post() [1/3]

QNetworkReply * QNetworkAccessManager::post ( const QNetworkRequest request,
QIODevice data 
)

Sends an HTTP POST request to the destination specified by request and returns a new QNetworkReply object opened for reading that will contain the reply sent by the server.

The contents of the data device will be uploaded to the server.

data must be open for reading and must remain valid until the finished() signal is emitted for this reply.

Note
Sending a POST request on protocols other than HTTP and HTTPS is undefined and will probably fail.
See also
get(), put(), deleteResource(), sendCustomRequest()

Definition at line 642 of file qnetworkaccessmanager.cpp.

Referenced by post(), and QDeclarativeXMLHttpRequest::requestFromUrl().

643 {
644  return d_func()->postProcess(createRequest(QNetworkAccessManager::PostOperation, request, data));
645 }
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData=0)
Returns a new QNetworkReply object to handle the operation op and request req.

◆ post() [2/3]

QNetworkReply * QNetworkAccessManager::post ( const QNetworkRequest request,
const QByteArray data 
)

Sends the contents of the data byte array to the destination specified by request.

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

Definition at line 656 of file qnetworkaccessmanager.cpp.

657 {
658  QBuffer *buffer = new QBuffer;
659  buffer->setData(data);
660  buffer->open(QIODevice::ReadOnly);
661 
662  QNetworkReply *reply = post(request, buffer);
663  buffer->setParent(reply);
664  return reply;
665 }
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
Definition: qbuffer.cpp:315
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
QNetworkReply * post(const QNetworkRequest &request, QIODevice *data)
Sends an HTTP POST request to the destination specified by request and returns a new QNetworkReply ob...

◆ post() [3/3]

QNetworkReply * QNetworkAccessManager::post ( const QNetworkRequest request,
QHttpMultiPart multiPart 
)

Sends the contents of the multiPart message to the destination specified by request.

Since
4.8

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

This can be used for sending MIME multipart messages over HTTP.

See also
QHttpMultiPart, QHttpPart, put()

Definition at line 682 of file qnetworkaccessmanager.cpp.

683 {
684  QNetworkRequest newRequest = d_func()->prepareMultipart(request, multiPart);
685  QIODevice *device = multiPart->d_func()->device;
686  QNetworkReply *reply = post(newRequest, device);
687  return reply;
688 }
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QNetworkReply * post(const QNetworkRequest &request, QIODevice *data)
Sends an HTTP POST request to the destination specified by request and returns a new QNetworkReply ob...
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66

◆ proxy()

QNetworkProxy QNetworkAccessManager::proxy ( ) const

Returns the QNetworkProxy that the requests sent using this QNetworkAccessManager object will use.

The default value for the proxy is QNetworkProxy::DefaultProxy.

See also
setProxy(), setProxyFactory(), proxyAuthenticationRequired()

Definition at line 414 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate::proxyAuthenticationRequired(), QNetworkAccessManagerPrivate::queryProxy(), and setProxy().

415 {
416  return d_func()->proxy;
417 }

◆ proxyAuthenticationRequired

void QNetworkAccessManager::proxyAuthenticationRequired ( const QNetworkProxy proxy,
QAuthenticator authenticator 
)
signal

This signal is emitted whenever a proxy requests authentication and QNetworkAccessManager cannot find a valid, cached credential.

The slot connected to this signal should fill in the credentials for the proxy proxy in the authenticator object.

QNetworkAccessManager will cache the credentials internally. The next time the proxy requests authentication, QNetworkAccessManager will automatically send the same credential without emitting the proxyAuthenticationRequired signal again.

If the proxy rejects the credentials, QNetworkAccessManager will emit the signal again.

See also
proxy(), setProxy(), authenticationRequired()

◆ proxyFactory()

QNetworkProxyFactory * QNetworkAccessManager::proxyFactory ( ) const
Since
4.5

Returns the proxy factory that this QNetworkAccessManager object is using to determine the proxies to be used for requests.

Note that the pointer returned by this function is managed by QNetworkAccessManager and could be deleted at any time.

See also
setProxyFactory(), proxy()

Definition at line 453 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate::queryProxy().

454 {
455  return d_func()->proxyFactory;
456 }

◆ put() [1/3]

QNetworkReply * QNetworkAccessManager::put ( const QNetworkRequest request,
QIODevice data 
)

Uploads the contents of data to the destination request and returnes a new QNetworkReply object that will be open for reply.

data must be opened for reading when this function is called and must remain valid until the finished() signal is emitted for this reply.

Whether anything will be available for reading from the returned object is protocol dependent. For HTTP, the server may send a small HTML page indicating the upload was successful (or not). Other protocols will probably have content in their replies.

Note
For HTTP, this request will send a PUT request, which most servers do not allow. Form upload mechanisms, including that of uploading files through HTML forms, use the POST mechanism.
See also
get(), post(), deleteResource(), sendCustomRequest()

Definition at line 732 of file qnetworkaccessmanager.cpp.

Referenced by put(), and QDeclarativeXMLHttpRequest::requestFromUrl().

733 {
734  return d_func()->postProcess(createRequest(QNetworkAccessManager::PutOperation, request, data));
735 }
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData=0)
Returns a new QNetworkReply object to handle the operation op and request req.

◆ put() [2/3]

QNetworkReply * QNetworkAccessManager::put ( const QNetworkRequest request,
const QByteArray data 
)

Sends the contents of the data byte array to the destination specified by request.

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

Definition at line 746 of file qnetworkaccessmanager.cpp.

747 {
748  QBuffer *buffer = new QBuffer;
749  buffer->setData(data);
750  buffer->open(QIODevice::ReadOnly);
751 
752  QNetworkReply *reply = put(request, buffer);
753  buffer->setParent(reply);
754  return reply;
755 }
QNetworkReply * put(const QNetworkRequest &request, QIODevice *data)
Uploads the contents of data to the destination request and returnes a new QNetworkReply object that ...
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
Definition: qbuffer.cpp:315
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950

◆ put() [3/3]

QNetworkReply * QNetworkAccessManager::put ( const QNetworkRequest request,
QHttpMultiPart multiPart 
)

Sends the contents of the multiPart message to the destination specified by request.

Since
4.8

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

This can be used for sending MIME multipart messages over HTTP.

See also
QHttpMultiPart, QHttpPart, post()

Definition at line 705 of file qnetworkaccessmanager.cpp.

706 {
707  QNetworkRequest newRequest = d_func()->prepareMultipart(request, multiPart);
708  QIODevice *device = multiPart->d_func()->device;
709  QNetworkReply *reply = put(newRequest, device);
710  return reply;
711 }
QNetworkReply * put(const QNetworkRequest &request, QIODevice *data)
Uploads the contents of data to the destination request and returnes a new QNetworkReply object that ...
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66

◆ sendCustomRequest()

QNetworkReply * QNetworkAccessManager::sendCustomRequest ( const QNetworkRequest request,
const QByteArray verb,
QIODevice data = 0 
)

Sends a custom request to the server identified by the URL of request.

Since
4.7

It is the user's responsibility to send a verb to the server that is valid according to the HTTP specification.

This method provides means to send verbs other than the common ones provided via get() or post() etc., for instance sending an HTTP OPTIONS command.

If data is not empty, the contents of the data device will be uploaded to the server; in that case, data must be open for reading and must remain valid until the finished() signal is emitted for this reply.

Note
This feature is currently available for HTTP(S) only.
See also
get(), post(), put(), deleteResource()

Definition at line 942 of file qnetworkaccessmanager.cpp.

943 {
944  QNetworkRequest newRequest(request);
945  newRequest.setAttribute(QNetworkRequest::CustomVerbAttribute, verb);
946  return d_func()->postProcess(createRequest(QNetworkAccessManager::CustomOperation, newRequest, data));
947 }
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData=0)
Returns a new QNetworkReply object to handle the operation op and request req.

◆ setCache()

void QNetworkAccessManager::setCache ( QAbstractNetworkCache cache)

Sets the manager's network cache to be the cache specified.

Since
4.5

The cache is used for all requests dispatched by the manager.

Use this function to set the network cache object to a class that implements additional features, like saving the cookies to permanent storage.

Note
QNetworkAccessManager takes ownership of the cache object.

QNetworkAccessManager by default does not have a set cache. Qt provides a simple disk cache, QNetworkDiskCache, which can be used.

See also
cache(), QNetworkRequest::CacheLoadControl

Definition at line 534 of file qnetworkaccessmanager.cpp.

535 {
537  if (d->networkCache != cache) {
538  delete d->networkCache;
539  d->networkCache = cache;
540  if (d->networkCache)
541  d->networkCache->setParent(this);
542  }
543 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractNetworkCache * cache() const
Returns the cache that is used to store data obtained from the network.
The QNetworkAccessManager class allows the application to send network requests and receive replies...

◆ setConfiguration()

void QNetworkAccessManager::setConfiguration ( const QNetworkConfiguration config)

Sets the network configuration that will be used when creating the QNetworkSession{network session} to config.

Since
4.7

The network configuration is used to create and open a network session before any request that requires network access is process. If no network configuration is explicitly set via this function the network configuration returned by QNetworkConfigurationManager::defaultConfiguration() will be used.

To restore the default network configuration set the network configuration to the value returned from QNetworkConfigurationManager::defaultConfiguration().

networkAccessManager->setConfiguration(manager.defaultConfiguration());

If an invalid network configuration is set, a network session will not be created. In this case network requests will be processed regardless, but may fail. For example:

networkAccessManager->setConfiguration(QNetworkConfiguration());
See also
configuration(), QNetworkSession

Definition at line 803 of file qnetworkaccessmanager.cpp.

804 {
805  d_func()->createSession(config);
806 }

◆ setCookieJar()

void QNetworkAccessManager::setCookieJar ( QNetworkCookieJar cookieJar)

Sets the manager's cookie jar to be the cookieJar specified.

The cookie jar is used by all requests dispatched by the manager.

Use this function to set the cookie jar object to a class that implements additional features, like saving the cookies to permanent storage.

Note
QNetworkAccessManager takes ownership of the cookieJar object.

If cookieJar is in the same thread as this QNetworkAccessManager, it will set the parent of the cookieJar so that the cookie jar is deleted when this object is deleted as well. If you want to share cookie jars between different QNetworkAccessManager objects, you may want to set the cookie jar's parent to 0 after calling this function.

QNetworkAccessManager by default does not implement any cookie policy of its own: it accepts all cookies sent by the server, as long as they are well formed and meet the minimum security requirements (cookie domain matches the request's and cookie path matches the request's). In order to implement your own security policy, override the QNetworkCookieJar::cookiesForUrl() and QNetworkCookieJar::setCookiesFromUrl() virtual functions. Those functions are called by QNetworkAccessManager when it detects a new cookie.

See also
cookieJar(), QNetworkCookieJar::cookiesForUrl(), QNetworkCookieJar::setCookiesFromUrl()

Definition at line 589 of file qnetworkaccessmanager.cpp.

590 {
592  d->cookieJarCreated = true;
593  if (d->cookieJar != cookieJar) {
594  if (d->cookieJar && d->cookieJar->parent() == this)
595  delete d->cookieJar;
596  d->cookieJar = cookieJar;
597  if (thread() == cookieJar->thread())
598  d->cookieJar->setParent(this);
599  }
600 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QNetworkAccessManager class allows the application to send network requests and receive replies...
if(void) toggleToolbarShown
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419

◆ setNetworkAccessible()

void QNetworkAccessManager::setNetworkAccessible ( QNetworkAccessManager::NetworkAccessibility  accessible)

Overrides the reported network accessibility.

Since
4.7

If accessible is NotAccessible the reported network accessiblity will always be NotAccessible. Otherwise the reported network accessibility will reflect the actual device state.

Definition at line 873 of file qnetworkaccessmanager.cpp.

874 {
876 
877  if (d->networkAccessible != accessible) {
879  d->networkAccessible = accessible;
881  if (previous != current)
883  }
884 }
double d
Definition: qnumeric_p.h:62
NetworkAccessibility networkAccessible() const
#define Q_D(Class)
Definition: qglobal.h:2482
NetworkAccessibility
Indicates whether the network is accessible via this network access manager.
#define emit
Definition: qobjectdefs.h:76
The QNetworkAccessManager class allows the application to send network requests and receive replies...
void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible)
This signal is emitted when the value of the networkAccessible property changes.

◆ setProxy()

void QNetworkAccessManager::setProxy ( const QNetworkProxy proxy)

Sets the proxy to be used in future requests to be proxy.

This does not affect requests that have already been sent. The proxyAuthenticationRequired() signal will be emitted if the proxy requests authentication.

A proxy set with this function will be used for all requests issued by QNetworkAccessManager. In some cases, it might be necessary to select different proxies depending on the type of request being sent or the destination host. If that's the case, you should consider using setProxyFactory().

See also
proxy(), proxyAuthenticationRequired()

Definition at line 433 of file qnetworkaccessmanager.cpp.

434 {
436  delete d->proxyFactory;
437  d->proxy = proxy;
438  d->proxyFactory = 0;
439 }
double d
Definition: qnumeric_p.h:62
QNetworkProxy proxy() const
Returns the QNetworkProxy that the requests sent using this QNetworkAccessManager object will use...
#define Q_D(Class)
Definition: qglobal.h:2482
The QNetworkAccessManager class allows the application to send network requests and receive replies...

◆ setProxyFactory()

void QNetworkAccessManager::setProxyFactory ( QNetworkProxyFactory factory)

Sets the proxy factory for this class to be factory.

Since
4.5

A proxy factory is used to determine a more specific list of proxies to be used for a given request, instead of trying to use the same proxy value for all requests.

All queries sent by QNetworkAccessManager will have type QNetworkProxyQuery::UrlRequest.

For example, a proxy factory could apply the following rules:

  • if the target address is in the local network (for example, if the hostname contains no dots or if it's an IP address in the organization's range), return QNetworkProxy::NoProxy
  • if the request is FTP, return an FTP proxy
  • if the request is HTTP or HTTPS, then return an HTTP proxy
  • otherwise, return a SOCKSv5 proxy server

The lifetime of the object factory will be managed by QNetworkAccessManager. It will delete the object when necessary.

Note
If a specific proxy is set with setProxy(), the factory will not be used.
See also
proxyFactory(), setProxy(), QNetworkProxyQuery

Definition at line 490 of file qnetworkaccessmanager.cpp.

491 {
493  delete d->proxyFactory;
494  d->proxyFactory = factory;
495  d->proxy = QNetworkProxy();
496 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QNetworkProxy class provides a network layer proxy.
The QNetworkAccessManager class allows the application to send network requests and receive replies...

◆ sslErrors

void QNetworkAccessManager::sslErrors ( QNetworkReply reply,
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 and reply is the QNetworkReply that is encountering these errors.

To indicate that the errors are not fatal and that the connection should proceed, the QNetworkReply::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(), QNetworkReply::sslErrors(), QNetworkReply::sslConfiguration(), QNetworkReply::ignoreSslErrors()

Referenced by QNetworkAccessManagerPrivate::postProcess().

Friends and Related Functions

◆ QNetworkAccessHttpBackend

Definition at line 162 of file qnetworkaccessmanager.h.

◆ QNetworkReplyImplPrivate

Definition at line 161 of file qnetworkaccessmanager.h.

Properties

◆ networkAccessible

QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccessible
private

whether the network is currently accessible via this network access manager.

Returns the current network accessibility.

Since
4.7

If the network is NotAccessible{not accessible} the network access manager will not process any new network requests, all such requests will fail with an error. Requests with URLs with the file:// scheme will still be processed.

By default the value of this property reflects the physical state of the device. Applications may override it to disable all network requests via this network access manager by calling

networkAccessManager->setNetworkAccessible(QNetworkAccessManager::NotAccessible);

Network requests can be reenabled again by calling

networkAccessManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
Note
Calling setNetworkAccessible() does not change the network state.
Since
4.7

Definition at line 77 of file qnetworkaccessmanager.h.


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