forked from qt-creator/qt-creator
Change the argument of TaskInterface::done() signal from bool into DoneResult. Make it consistent with other TaskTree API. Introduce toDoneResult(bool success) helper. Change-Id: I7b3041d7c1ed0317c76adbc1fd37448231e85f82 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
39 lines
1021 B
C++
39 lines
1021 B
C++
// 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(DoneResult::Error);
|
|
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(toDoneResult(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
|