Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlnetworkaccessmanagerfactory.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
include
"qqmlnetworkaccessmanagerfactory.h"
6
7
QT_BEGIN_NAMESPACE
8
9
#
if
QT_CONFIG
(
qml_network
)
10
11
/*!
12
\class QQmlNetworkAccessManagerFactory
13
\since 5.0
14
\inmodule QtQml
15
\brief The QQmlNetworkAccessManagerFactory class creates QNetworkAccessManager instances for a QML engine.
16
17
A QML engine uses QNetworkAccessManager for all network access.
18
By implementing a factory, it is possible to provide the QML engine
19
with custom QNetworkAccessManager instances with specialized caching,
20
proxy and cookies support.
21
22
\list
23
\li The QNetworkDiskCache can be used as a request cache with \l {QNetworkDiskCache}.
24
\li Using \l {QNetworkProxy}, traffic sent by the QNetworkAccessManager can be tunnelled through a proxy.
25
\li Cookies can be saved for future requests by adding a \l {QNetworkCookieJar}.
26
\endlist
27
28
To implement a factory, subclass QQmlNetworkAccessManagerFactory and
29
implement the virtual create() method, then assign it to the relevant QML
30
engine using QQmlEngine::setNetworkAccessManagerFactory(). For instance, the QNetworkAccessManager
31
objects created by the following snippet will cache requests.
32
\snippet code/src_network_access_qnetworkaccessmanager.cpp 0
33
34
The factory can then be passed to the QML engine so it can instantiate the QNetworkAccessManager with the custom behavior.
35
\snippet code/src_network_access_qnetworkaccessmanager.cpp 1
36
37
Note the QML engine may create QNetworkAccessManager instances
38
from multiple threads. Because of this, the implementation of the create()
39
method must be \l{Reentrancy and Thread-Safety}{reentrant}. In addition,
40
the developer should be careful if the signals of the object to be
41
returned from create() are connected to the slots of an object that may
42
be created in a different thread:
43
44
\list
45
\li The QML engine internally handles all requests, and cleans up any
46
QNetworkReply objects it creates. Receiving the
47
QNetworkAccessManager::finished() signal in another thread may not
48
provide the receiver with a valid reply object if it has already
49
been deleted.
50
\li Authentication details provided to QNetworkAccessManager::authenticationRequired()
51
must be provided immediately, so this signal cannot be connected as a
52
Qt::QueuedConnection (or as the default Qt::AutoConnection from another
53
thread).
54
\endlist
55
56
For more information about signals and threads, see
57
\l {Threads and QObjects} and \l {Signals and Slots Across Threads}.
58
59
\sa QNetworkDiskCache
60
*/
61
62
/*!
63
Destroys the factory. The default implementation does nothing.
64
*/
65
QQmlNetworkAccessManagerFactory::~QQmlNetworkAccessManagerFactory()
66
{
67
}
68
69
/*!
70
\fn QNetworkAccessManager *QQmlNetworkAccessManagerFactory::create(QObject *parent)
71
72
Creates and returns a network access manager with the specified \a parent.
73
This method must return a new QNetworkAccessManager instance each time
74
it is called.
75
76
Note: this method may be called by multiple threads, so ensure the
77
implementation of this method is reentrant.
78
*/
79
80
#
endif
// qml_network
81
82
QT_END_NAMESPACE
qtdeclarative
src
qml
qml
qqmlnetworkaccessmanagerfactory.cpp
Generated on
for Qt by
1.16.1