diff options
Diffstat (limited to 'src/network/doc/snippets')
11 files changed, 137 insertions, 25 deletions
diff --git a/src/network/doc/snippets/CMakeLists.txt b/src/network/doc/snippets/CMakeLists.txt index 97574156ad..05e5668e24 100644 --- a/src/network/doc/snippets/CMakeLists.txt +++ b/src/network/doc/snippets/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) diff --git a/src/network/doc/snippets/code/doc_src_qtnetwork.cpp b/src/network/doc/snippets/code/doc_src_qtnetwork.cpp deleted file mode 100644 index dae56d5db5..0000000000 --- a/src/network/doc/snippets/code/doc_src_qtnetwork.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//! [1] -#include <QtNetwork> -//! [1] diff --git a/src/network/doc/snippets/code/src_network_access_qhttpmultipart.cpp b/src/network/doc/snippets/code/src_network_access_qhttpmultipart.cpp index cf51c68861..73308b5547 100644 --- a/src/network/doc/snippets/code/src_network_access_qhttpmultipart.cpp +++ b/src/network/doc/snippets/code/src_network_access_qhttpmultipart.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause //! [0] QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); diff --git a/src/network/doc/snippets/code/src_network_access_qhttppart.cpp b/src/network/doc/snippets/code/src_network_access_qhttppart.cpp index 38d1b7aff0..059a4c60e9 100644 --- a/src/network/doc/snippets/code/src_network_access_qhttppart.cpp +++ b/src/network/doc/snippets/code/src_network_access_qhttppart.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause //! [0] Content-Type: text/plain diff --git a/src/network/doc/snippets/code/src_network_access_qnetworkrequestfactory.cpp b/src/network/doc/snippets/code/src_network_access_qnetworkrequestfactory.cpp new file mode 100644 index 0000000000..f7994d442c --- /dev/null +++ b/src/network/doc/snippets/code/src_network_access_qnetworkrequestfactory.cpp @@ -0,0 +1,27 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +using namespace Qt::StringLiterals; + +//! [0] +// Instantiate a factory somewhere suitable in the application +QNetworkRequestFactory api{{"https://example.com/v1"_L1}}; + +// Set bearer token +api.setBearerToken("my_token"); + +// Issue requests (reply handling omitted for brevity) +manager.get(api.createRequest("models"_L1)); // https://example.com/v1/models +// The conventional leading '/' for the path can be used as well +manager.get(api.createRequest("/models"_L1)); // https://example.com/v1/models +//! [0] + + +//! [1] +// Here the API version v2 is used as the base path: +QNetworkRequestFactory api{{"https://example.com/v2"_L1}}; +// ... +manager.get(api.createRequest("models"_L1)); // https://example.com/v2/models +// Equivalent with a leading '/' +manager.get(api.createRequest("/models"_L1)); // https://example.com/v2/models +//! [1] + diff --git a/src/network/doc/snippets/code/src_network_access_qrestaccessmanager.cpp b/src/network/doc/snippets/code/src_network_access_qrestaccessmanager.cpp new file mode 100644 index 0000000000..8f9e00f4b6 --- /dev/null +++ b/src/network/doc/snippets/code/src_network_access_qrestaccessmanager.cpp @@ -0,0 +1,104 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +//! [0] +QNetworkReply *reply = manager->get(request); +QObject::connect(reply, &QNetworkReply::finished, this, [reply]() { + // The reply may be wrapped in the finish handler: + QRestReply restReply(reply); + if (restReply.isSuccess()) + // ... +}); +//! [0] + + +//! [1] +// With lambda +manager->get(request, this, [this](QRestReply &reply) { + if (reply.isSuccess()) { + // ... + } +}); +// With member function +manager->get(request, this, &MyClass::handleFinished); +//! [1] + + +//! [2] +QJsonDocument myJson; +// ... +manager->post(request, myJson, this, [this](QRestReply &reply) { + if (!reply.isSuccess()) { + // ... + } + if (std::optional json = reply.readJson()) { + // use *json + } +}); +//! [2] + + +//! [3] +manager->get(request, this, [this](QRestReply &reply) { + if (!reply.isSuccess()) + // handle error + if (std::optional json = reply.readJson()) + // use *json +}); +//! [3] + + +//! [4] +manager->get(request, myData, this, [this](QRestReply &reply) { + if (reply.isSuccess()) + // ... +}); +//! [4] + + +//! [5] +manager->post(request, myData, this, [this](QRestReply &reply) { + if (reply.isSuccess()) + // ... +}); +//! [5] + + +//! [6] +manager->put(request, myData, this, [this](QRestReply &reply) { + if (reply.isSuccess()) + // ... +}); +//! [6] + + +//! [7] +manager->head(request, this, [this](QRestReply &reply) { + if (reply.isSuccess()) + // ... +}); +//! [7] + + +//! [8] +manager->deleteResource(request, this, [this](QRestReply &reply) { + if (reply.isSuccess()) + // ... +}); +//! [8] + + +//! [9] +manager->sendCustomRequest(request, "MYMETHOD", myData, this, [this](QRestReply &reply) { + if (reply.isSuccess()) + // ... +}); +//! [9] + + +//! [10] +manager->patch(request, myData, this, [this](QRestReply &reply) { + if (reply.isSuccess()) + // ... +}); +//! [10] diff --git a/src/network/doc/snippets/code/src_network_kernel_qnetworkinterface.cpp b/src/network/doc/snippets/code/src_network_kernel_qnetworkinterface.cpp index 4f3839532d..d34750aaaf 100644 --- a/src/network/doc/snippets/code/src_network_kernel_qnetworkinterface.cpp +++ b/src/network/doc/snippets/code/src_network_kernel_qnetworkinterface.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause //! [0] QNetworkInterface::interfaceFromName(name).index() diff --git a/src/network/doc/snippets/code/src_network_ssl_qsslconfiguration.cpp b/src/network/doc/snippets/code/src_network_ssl_qsslconfiguration.cpp index edc542ac3f..d9a493d1ce 100644 --- a/src/network/doc/snippets/code/src_network_ssl_qsslconfiguration.cpp +++ b/src/network/doc/snippets/code/src_network_ssl_qsslconfiguration.cpp @@ -6,10 +6,3 @@ QSslConfiguration config = sslSocket.sslConfiguration(); config.setProtocol(QSsl::TlsV1_2); sslSocket.setSslConfiguration(config); //! [0] - - -//! [1] -QSslConfiguration tlsConfig = QSslConfiguration::defaultConfiguration(); -tlsConfig.setCiphers(QStringLiteral("DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA")); -//! [1] - diff --git a/src/network/doc/snippets/code/src_network_ssl_qsslpresharedkeyauthenticator.cpp b/src/network/doc/snippets/code/src_network_ssl_qsslpresharedkeyauthenticator.cpp index 1af356ee00..b3242e057d 100644 --- a/src/network/doc/snippets/code/src_network_ssl_qsslpresharedkeyauthenticator.cpp +++ b/src/network/doc/snippets/code/src_network_ssl_qsslpresharedkeyauthenticator.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause //! [0] connect(socket, &QSslSocket::preSharedKeyAuthenticationRequired, diff --git a/src/network/doc/snippets/code/src_network_ssl_qsslsocket.cpp b/src/network/doc/snippets/code/src_network_ssl_qsslsocket.cpp index 89d82d66f8..eed032589e 100644 --- a/src/network/doc/snippets/code/src_network_ssl_qsslsocket.cpp +++ b/src/network/doc/snippets/code/src_network_ssl_qsslsocket.cpp @@ -49,12 +49,6 @@ socket->write("1 CAPABILITY\r\n"); //! [3] -//! [4] -QSslSocket socket; -socket.setCiphers("DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA"); -//! [4] - - //! [5] socket->connectToHostEncrypted("imap", 993); if (socket->waitForEncrypted(1000)) diff --git a/src/network/doc/snippets/network/CMakeLists.txt b/src/network/doc/snippets/network/CMakeLists.txt index be403e79b1..b75aeafea0 100644 --- a/src/network/doc/snippets/network/CMakeLists.txt +++ b/src/network/doc/snippets/network/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause add_library(network_cppsnippets OBJECT tcpwait.cpp) |