1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5 \page network-changes-qt6.html
6 \title Changes to Qt Network
7 \ingroup changes-qt-5-to-6
8 \brief Migrate Qt Network to Qt 6.
10 Qt 6 is a result of the conscious effort to make the framework more
11 efficient and easy to use.
13 We try to maintain binary and source compatibility for all the public
14 APIs in each release. But some changes were inevitable in an effort to
15 make Qt a better framework.
17 In this topic we summarize those changes in Qt Network, and provide
18 guidance to handle them.
22 \section2 Ambiguous name overloads
24 Several ambiguous overloaded functions are removed. The error() signal
25 is replaced by errorOccurred() in QAbstractSocket and its heirs
26 (QTcpSocket, QUdpSocket, QLocalSocket, and QSslSocket), and in QNetworkReply.
30 connect(socket, qOverload<QAbstractSocket::SocketError>(&QAbstractSocket::error),
31 this, &SomeClass::errorSlot);
34 must therefore be changed to:
37 connect(socket, &QAbstractSocket::errorOccurred, this, &SomeClass::errorSlot);
40 In QSslSocket, the function that returns a list of errors encountered
41 during the TLS handshake:
44 QList<QSslError> sslErrors() const;
47 is renamed to sslHandshakeErrors():
50 const auto tlsErrors = socket.sslHandshakeErrors();
53 \section2 Bearer management is removed
55 The classes QNetworkConfiguration and QNetworkConfigurationManager are removed in Qt 6.
56 Consequently, the following member functions of QNetworkAccessManager are also removed:
59 void setConfiguration(const QNetworkConfiguration &config);
60 QNetworkConfiguration configuration() const;
61 QNetworkConfiguration activeConfiguration() const;
62 void setNetworkAccessible(NetworkAccessibility accessible);
63 NetworkAccessibility networkAccessible() const;
64 void networkSessionConnected();
67 QNetworkInformation, initially introduced in Qt 6.1, aims to replace some
68 aspects of the bearer management API. It works by providing a unified API
69 which subscribes to changes to the network as notified by the operating
72 QNetworkInformation::reachability(), introduced in Qt 6.1, replaces the
73 QNetworkAccessManager::networkAccessible() function, while adding more
74 detailed information about the reachability of the network. See its
75 documentation for more details.
77 In Qt 6.2 QNetworkInformation gained the ability to detect captive portals.
79 In Qt 6.3 QNetworkInformation gained QNetworkInformation::transportMedium()
80 and QNetworkInformation::isMetered().
82 \section2 Deleted enumerators
84 Several enumerators are removed in QtNetwork. This includes constants
85 for no longer supported protocols and functionality:
91 \li QNetworkRequest::SpdyAllowedAttribute;
92 \li QNetworkRequest::SpdyWasUsedAttribute;
93 \li QNetworkAccessManager::UnknownAccessibility;
94 \li QNetworkAccessManager::NotAccessible;
95 \li QNetworkAccessManager::Accessible
98 and enumerators whose names did not follow proper naming conventions:
101 \li QSsl::TlsV1 (QSsl::TlsV1_0 is the proper name);
102 \li QNetworkRequest::HTTP2AllowedAttribute (use QNetworkRequest::Http2AllowedAttribute);
103 \li QNetworkRequest::HTTP2WasUsedAttribute (use QNetworkRequest::Http2WasUsedAttribute).
106 QNetworkRequest::FollowRedirectsAttribute is removed in Qt 6, see
107 \l {Redirect policies}{the section about redirects handling} below.
109 \section2 Configuring QSslSocket
111 The following deprecated functions are removed in Qt 6:
114 QList<QSslCipher> ciphers() const;
115 void setCiphers(const QList<QSslCipher> &ciphers);
116 void setCiphers(const QString &ciphers);
117 static void setDefaultCiphers(const QList<QSslCipher> &ciphers);
118 static QList<QSslCipher> defaultCiphers();
119 static QList<QSslCipher> supportedCiphers();
120 QList<QSslCipher> ciphers() const;
121 void setCiphers(const QList<QSslCipher> &ciphers);
122 void setCiphers(const QString &ciphers);
123 static void setDefaultCiphers(const QList<QSslCipher> &ciphers);
124 static QList<QSslCipher> defaultCiphers();
125 static QList<QSslCipher> supportedCiphers();
126 bool addCaCertificates(const QString &path, QSsl::EncodingFormat format = QSsl::Pem,
127 QRegExp::PatternSyntax syntax = QRegExp::FixedString);
128 void addCaCertificate(const QSslCertificate &certificate);
129 void addCaCertificates(const QList<QSslCertificate> &certificates);
130 void setCaCertificates(const QList<QSslCertificate> &certificates);
131 QList<QSslCertificate> caCertificates() const;
132 static bool addDefaultCaCertificates(const QString &path, QSsl::EncodingFormat format = QSsl::Pem,
133 QRegExp::PatternSyntax syntax = QRegExp::FixedString);
134 static void addDefaultCaCertificate(const QSslCertificate &certificate);
135 static void addDefaultCaCertificates(const QList<QSslCertificate> &certificates);
136 static void setDefaultCaCertificates(const QList<QSslCertificate> &certificates);
137 static QList<QSslCertificate> defaultCaCertificates();
138 static QList<QSslCertificate> systemCaCertificates();
141 Use QSslConfiguration and its member functions to set these parameters, e.g.:
144 auto sslConfiguration = QSslConfiguration::defaultConfiguration();
145 sslConfiguration.setCiphers("ECDHE-ECDSA-AES256-SHA384");
146 // Set other parameters here ...
147 socket.setSslConfiguration(sslConfiguration);
150 \section1 Changes in QNetworkAccessManager's default behavior
152 \section2 Redirect policies
154 In Qt 6, the default redirect policy has changed from manual to
155 QNetworkRequest::NoLessSafeRedirectPolicy. If your application relies
156 on manual redirect handling (it connects its slot to the QNetworkReply::redirected
157 signal), you have to explicitly set this policy when creating a request:
160 request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::ManualRedirectPolicy);
163 \section2 HTTP/2 is enabled by default
165 In Qt 6 QNetworkAccessManager enables HTTP/2 protocol by default. Depending on the
166 scheme ("https" or "http"), QNetworkAccessManager will use the Application Layer
167 Protocol Negotiation TLS extension or "protocol upgrade" HTTP header to negotiate HTTP/2.
168 If HTTP/2 cannot be negotiated, the access manager will fall back to using HTTP/1.1.
169 If your application can only use HTTP/1.1, you have to disable HTTP/2 manually
173 request.setAttribute(QNetworkRequest::Http2AllowedAttribute, false);
176 \section2 QNetworkAccessManager now guards against archive bombs
178 Starting with Qt 6.2 QNetworkAccessManager will guard against compressed
179 files that decompress to files which are much larger than their compressed
180 form by erroring out the reply if the decompression ratio exceeds a certain
182 This check is only applied to files larger than a certain size, which can be
183 customized (or disabled by passing -1) by calling
184 \l{QNetworkRequest::setDecompressedSafetyCheckThreshold()}.