CopperSpice API  1.7.2
QNetworkAccessManager Class Reference

Allows the application to send network requests and receive replies. More...

Inheritance diagram for QNetworkAccessManager:
QObject

Public Types

enum  NetworkAccessibility
 
enum  Operation
 

Public Signals

void authenticationRequired (QNetworkReply *reply, QAuthenticator *authenticator)
 
void encrypted (QNetworkReply *reply)
 
void finished (QNetworkReply *reply)
 
void networkAccessibleChanged (QNetworkAccessManager::NetworkAccessibility accessible)
 
void preSharedKeyAuthenticationRequired (QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator)
 
void proxyAuthenticationRequired (const QNetworkProxy &proxy, QAuthenticator *authenticator)
 
void sslErrors (QNetworkReply *reply, const QList< QSslError > &errors)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Methods

 QNetworkAccessManager (QObject *parent=nullptr)
 
 ~QNetworkAccessManager ()
 
QNetworkConfiguration activeConfiguration () const
 
QAbstractNetworkCachecache () const
 
void clearAccessCache ()
 
QNetworkConfiguration configuration () const
 
void connectToHost (const QString &hostName, quint16 port=80)
 
void connectToHostEncrypted (const QString &hostName, quint16 port=443, const QSslConfiguration &sslConfiguration=QSslConfiguration::defaultConfiguration ())
 
QNetworkCookieJarcookieJar () const
 
QNetworkReplydeleteResource (const QNetworkRequest &request)
 
QNetworkReplyget (const QNetworkRequest &request)
 
QNetworkReplyhead (const QNetworkRequest &request)
 
NetworkAccessibility networkAccessible () const
 
QNetworkReplypost (const QNetworkRequest &request, const QByteArray &data)
 
QNetworkReplypost (const QNetworkRequest &request, QHttpMultiPart *multiPart)
 
QNetworkReplypost (const QNetworkRequest &request, QIODevice *data)
 
QNetworkProxy proxy () const
 
QNetworkProxyFactoryproxyFactory () const
 
QNetworkReplyput (const QNetworkRequest &request, const QByteArray &data)
 
QNetworkReplyput (const QNetworkRequest &request, QHttpMultiPart *multiPart)
 
QNetworkReplyput (const QNetworkRequest &request, QIODevice *data)
 
QNetworkReplysendCustomRequest (const QNetworkRequest &request, const QByteArray &verb, QIODevice *data=nullptr)
 
void setCache (QAbstractNetworkCache *cache)
 
void setConfiguration (const QNetworkConfiguration &config)
 
void setCookieJar (QNetworkCookieJar *cookieJar)
 
void setProxy (const QNetworkProxy &proxy)
 
void setProxyFactory (QNetworkProxyFactory *factory)
 
virtual QStringList supportedSchemes () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Protected Slots

QStringList supportedSchemesImplementation ()
 

Protected Methods

virtual QNetworkReplycreateRequest (Operation op, const QNetworkRequest &request, QIODevice *outgoingData=nullptr)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Properties

 networkAccessible
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 

Detailed Description

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 CopperSpice application.

Once a QNetworkAccessManager object has been created, the application can use it to send requests over the network. A group of standard methods 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 from the network can be accomplished with the following code.

connect(manager, &QNetworkAccessManager::finished, this, &MyClass::replyFinished);
manager->get(QNetworkRequest(QUrl("https://www.copperspice.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.).

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() method.

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.

The following example is a bit more involved however it assumes the manager was already created.

request.setUrl(QUrl("https://www.copperspice.com"));
request.setRawHeader("User-Agent", "MyBrowser 1.0");
QNetworkReply *reply = manager->get(request);
connect(reply, &QIODevice::readyRead, this, &MyClass::slotReadyRead);
connect(reply, &QNetworkReply::error, this, &MyClass::slotError);
connect(reply, &QNetworkReply::sslErrors, this, &MyClass::slotSslErrors);
Note
See also
QNetworkRequest, QNetworkReply, QNetworkProxy

Member Enumeration Documentation

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

ConstantValueDescription
QNetworkAccessManager::UnknownAccessibility-1 Can not be determined
QNetworkAccessManager::NotAccessible0 Network is not currently accessible, either because there is no network coverage or access has been disabled by a call to setNetworkAccessible()
QNetworkAccessManager::Accessible1The network is accessible.
See also
networkAccessible

Indicates the operation this reply is processing.

ConstantValueDescription
QNetworkAccessManager::HeadOperation1 Retrieve headers operation (created with head())
QNetworkAccessManager::GetOperation2 Retrieve headers and download contents (created with get())
QNetworkAccessManager::PutOperation3 Upload contents operation (created with put())
QNetworkAccessManager::PostOperation4 Send the contents of an HTML form for processing via HTTP POST (created with post())
QNetworkAccessManager::DeleteOperation5 Delete contents operation (created with deleteResource())
QNetworkAccessManager::CustomOperation6 Custom operation (created with sendCustomRequest())
See also
QNetworkReply::operation()

Constructor & Destructor Documentation

QNetworkAccessManager::QNetworkAccessManager ( QObject parent = nullptr)
explicit

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

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 do not call QObject::setParent() on them.

Method Documentation

QNetworkConfiguration QNetworkAccessManager::activeConfiguration ( ) const

Returns the current active network configuration.

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

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

See also
configuration()
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()
QAbstractNetworkCache * QNetworkAccessManager::cache ( ) const

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

See also
setCache()
void QNetworkAccessManager::clearAccessCache ( )

Flushes the internal cache of authentication data and network connections. This method is useful for doing auto tests.

See also
clearConnectionCache()
QNetworkConfiguration QNetworkAccessManager::configuration ( ) const

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

See also
setConfiguration(), activeConfiguration()
void QNetworkAccessManager::connectToHost ( const QString hostName,
quint16  port = 80 
)

Initiates a connection to the host given by hostName at port port. This method is useful to complete the TCP handshake to a host before the HTTP request is made, resulting in a lower network latency.

This method has no possibility to report errors.

See also
connectToHostEncrypted(), get(), post(), put(), deleteResource()
void QNetworkAccessManager::connectToHostEncrypted ( const QString hostName,
quint16  port = 443,
const QSslConfiguration sslConfiguration = QSslConfiguration::defaultConfiguration() 
)

Initiates a connection to the host given by hostName at port port, using sslConfiguration. This method is useful to complete the TCP and SSL handshake to a host before the HTTPS request is made, resulting in a lower network latency.

Preconnecting a SPDY connection can be done by calling setAllowedNextProtocols() on sslConfiguration with QSslConfiguration::NextProtocolSpdy3_0 contained in the list of allowed protocols. When using SPDY, one single connection per host is enough, i.e. calling this method multiple times per host will not result in faster network transactions.

This method has no possibility to report errors.

See also
connectToHost(), get(), post(), put(), deleteResource()
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()
QNetworkReply * QNetworkAccessManager::createRequest ( Operation  op,
const QNetworkRequest request,
QIODevice outgoingData = nullptr 
)
protectedvirtual

Returns a new QNetworkReply object to handle the operation op and request request. The device outgoingData is always a nullptr 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.

QNetworkReply * QNetworkAccessManager::deleteResource ( const QNetworkRequest request)

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

This feature is currently available for HTTP only, performing an HTTP DELETE request.

See also
get(), post(), put(), sendCustomRequest()
void QNetworkAccessManager::encrypted ( QNetworkReply reply)
signal

This signal is emitted when an SSL/TLS session has successfully completed the initial handshake. At this point, no user data has been transmitted. The signal can be used to perform additional checks on the certificate chain, for example to notify users when the certificate for a website has changed. The reply parameter specifies which network reply is responsible. If the reply does not match the expected criteria then it should be aborted by calling QNetworkReply::abort() by a slot connected to this signal. The SSL configuration in use can be inspected using the QNetworkReply::sslConfiguration() method.

Internally, QNetworkAccessManager may open multiple connections to a server, in order to allow it process requests in parallel. These connections may be reused, which means that the encrypted() signal would not be emitted. This means that you are only guaranteed to receive this signal for the first connection to a site in the lifespan of the QNetworkAccessManager.

See also
QSslSocket::encrypted(), QNetworkReply::encrypted()
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.

You should not delete the reply object in the slot connected to this signal, use deleteLater().

Refer to QNetworkReply::finished() for information on the status the object will be in.

See also
QNetworkReply::error()
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()
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 method is named after the HTTP request associated (HEAD).

NetworkAccessibility QNetworkAccessManager::networkAccessible ( ) const

Returns the current network accessibility. Getter method for property networkAccessible.

See also
setNetworkAccessible()
void QNetworkAccessManager::networkAccessibleChanged ( QNetworkAccessManager::NetworkAccessibility  accessible)
signal

This signal is emitted when the value of the networkAccessible property changes. The given accessible is the new network accessibility.

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

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

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

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

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

See also
QHttpMultiPart, QHttpPart, put()
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.

The given data must be open for reading and must remain valid until the finished() signal is emitted for this reply. Sending a POST request on protocols other than HTTP and HTTPS is undefined and will probably fail.

See also
get(), put(), deleteResource(), sendCustomRequest()
void QNetworkAccessManager::preSharedKeyAuthenticationRequired ( QNetworkReply reply,
QSslPreSharedKeyAuthenticator authenticator 
)
signal

This signal is emitted if the SSL/TLS handshake negotiates a PSK ciphersuite, and therefore a PSK authentication is then required. The reply object is the QNetworkReply that is negotiating such ciphersuites.

When using PSK, the client must send to the server a valid identity and a valid pre shared key, in order for the SSL handshake to continue. Applications can provide this information in a slot connected to this signal, by filling in the passed authenticator object according to their needs.

Ignoring this signal or failing to provide the required credentials will cause the handshake to fail, and therefore the connection to be aborted. The authenticator object is owned by the reply and must not be deleted by the application.

See also
QSslPreSharedKeyAuthenticator
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()
void QNetworkAccessManager::proxyAuthenticationRequired ( const QNetworkProxy proxy,
QAuthenticator authenticator 
)
signal

This signal is emitted whenever a proxy requests authentication and QNetworkAccessManager can not 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()
QNetworkProxyFactory * QNetworkAccessManager::proxyFactory ( ) const

Returns the proxy factory that this QNetworkAccessManager object is using to determine the proxies to be used for requests. The pointer returned by this method is managed by QNetworkAccessManager and could be deleted at any time.

See also
setProxyFactory(), proxy()
QNetworkReply * QNetworkAccessManager::put ( const QNetworkRequest request,
const QByteArray data 
)

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

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

Sends the contents of the multiPart message to the destination specified by request. This can be used for sending MIME multipart messages over HTTP.

See also
QHttpMultiPart, QHttpPart, post()
QNetworkReply * QNetworkAccessManager::put ( const QNetworkRequest request,
QIODevice data 
)

Uploads the contents of data to the destination request and returns a new QNetworkReply object that will be open for reply. The data must be opened for reading when this method 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()
QNetworkReply * QNetworkAccessManager::sendCustomRequest ( const QNetworkRequest request,
const QByteArray verb,
QIODevice data = nullptr 
)

Sends a custom request to the server identified by the URL of request. It is the responsibility of the user 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()
void QNetworkAccessManager::setCache ( QAbstractNetworkCache cache)

Sets the manager's network cache to be the cache specified. The cache is used for all requests dispatched by the manager. Use this method to set the network cache object to a class that implements additional features, like saving the cookies to permanent storage.

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

QNetworkAccessManager will take ownership of the cache object.

See also
cache(), QNetworkRequest::CacheLoadControl
void QNetworkAccessManager::setConfiguration ( const QNetworkConfiguration config)

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

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 method 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.

networkAccessManager->setConfiguration(QNetworkConfiguration());
See also
configuration(), QNetworkSession
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 method to set the cookie jar object to a class that implements additional features, like saving the cookies to permanent storage.

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 method.

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 methods. Those methods are called by QNetworkAccessManager when it detects a new cookie.

QNetworkAccessManager will take ownership of the cookieJar object.

See also
cookieJar(), QNetworkCookieJar::cookiesForUrl(), QNetworkCookieJar::setCookiesFromUrl()
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 method 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()
void QNetworkAccessManager::setProxyFactory ( QNetworkProxyFactory factory)

Sets the proxy factory for this class to be factory. 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.

The lifetime of the object factory will be managed by QNetworkAccessManagerw which will delete the object when necessary. If a specific proxy is set with setProxy() the factory will not be used.

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 return QNetworkProxy::NoProxy (For example, if the hostname contains no dots or if it's an IP address in the organization's range)
  • If the request is FTP, returns an FTP proxy
  • If the request is HTTP or HTTPS, returns an HTTP proxy
  • Otherwise, returns a SOCKSv5 proxy server
See also
proxyFactory(), setProxy(), QNetworkProxyQuery
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() method 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()
QStringList QNetworkAccessManager::supportedSchemes ( ) const
virtual

Lists all the URL schemes supported by the access manager.

See also
supportedSchemesImplementation()
QStringList QNetworkAccessManager::supportedSchemesImplementation ( )
protectedslot

Lists all the URL schemes supported by the access manager. You should not call this method directly, use QNetworkAccessManager::supportedSchemes() instead.

Reimplement this slot to provide your own supported schemes in a QNetworkAccessManager subclass. It is for instance necessary when your subclass provides support for new protocols.

See also
supportedSchemes()

Property Documentation

QNetworkAccessManager::networkAccessible

This property holds whether the network is currently accessible via this network access manager. Calling setNetworkAccessible() does not change the network state.

If the network is 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);
PropertiesClass Methods
read networkAccessible
write setNetworkAccessible
notify networkAccessibleChanged