Tasking: Introduce NetworkQuery

The NetworkQuery class is prepared to work with TaskTree.
Provide the task tree adapter for the NetworkQuery class.
Register the task inside the Tasking namespace under
the NetworkQueryTask name.

This class introduces the dependency to Qt::Network,
otherwise Tasking namespace is independent on Qt::Network.
Possibly, may be added into Qt::Network lib,
as a wrapper around the QNetworkReply.

Change-Id: I29f160c0bf128c567ce20f044540b2dd6f1e17c4
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Jarek Kobus
2023-06-02 23:56:50 +02:00
parent 73791080d4
commit 9694d9c6f6
8 changed files with 102 additions and 5 deletions

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "networkquery.h"
#include <QNetworkAccessManager>
namespace Tasking {
void NetworkQuery::start()
{
if (m_reply) {
qWarning("The NetworkQuery is already running. Ignoring the call to start().");
return;
}
if (!m_manager) {
qWarning("Can't start the NetworkQuery without the QNetworkAccessManager. "
"Stopping with an error.");
emit done(false);
return;
}
m_reply.reset(m_manager->get(m_request));
connect(m_reply.get(), &QNetworkReply::finished, this, [this] {
disconnect(m_reply.get(), nullptr, this, nullptr);
emit done(m_reply->error() == QNetworkReply::NoError);
m_reply.release()->deleteLater();
});
if (m_reply->isRunning())
emit started();
}
NetworkQuery::~NetworkQuery()
{
if (m_reply)
m_reply->abort();
}
} // namespace Tasking