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
networkquery.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 Jarek Kobus
2// Copyright (C) 2024 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "networkquery.h"
6
7#include <QtNetwork/QNetworkAccessManager>
8
10
11namespace Tasking {
12
14{
15 if (m_reply) {
16 qWarning("The NetworkQuery is already running. Ignoring the call to start().");
17 return;
18 }
19 if (!m_manager) {
20 qWarning("Can't start the NetworkQuery without the QNetworkAccessManager. "
21 "Stopping with an error.");
22 emit done(DoneResult::Error);
23 return;
24 }
25 switch (m_operation) {
26 case NetworkOperation::Get:
27 m_reply.reset(m_manager->get(m_request));
28 break;
29 case NetworkOperation::Put:
30 m_reply.reset(m_manager->put(m_request, m_writeData));
31 break;
32 case NetworkOperation::Post:
33 m_reply.reset(m_manager->post(m_request, m_writeData));
34 break;
35 case NetworkOperation::Delete:
36 m_reply.reset(m_manager->deleteResource(m_request));
37 break;
38 }
39
40 connect(m_reply.get(), &QNetworkReply::downloadProgress, this, &NetworkQuery::downloadProgress);
41#if QT_CONFIG(ssl)
42 connect(m_reply.get(), &QNetworkReply::sslErrors, this, &NetworkQuery::sslErrors);
43#endif
44 connect(m_reply.get(), &QNetworkReply::finished, this, [this] {
45 disconnect(m_reply.get(), &QNetworkReply::finished, this, nullptr);
46 emit done(toDoneResult(m_reply->error() == QNetworkReply::NoError));
47 m_reply.release()->deleteLater();
48 });
49 if (m_reply->isRunning())
50 emit started();
51}
52
53NetworkQuery::~NetworkQuery()
54{
55 if (m_reply) {
56 disconnect(m_reply.get(), nullptr, this, nullptr);
57 m_reply->abort();
58 }
59}
60
61} // namespace Tasking
62
63QT_END_NAMESPACE
\inmodule TaskingSolution