fix: network requests timing out too early (#5729)

This commit is contained in:
pajlada
2024-11-23 16:29:44 +01:00
committed by GitHub
parent b4ff1286c7
commit 14c4bb6459
4 changed files with 79 additions and 10 deletions
+23 -10
View File
@@ -30,22 +30,35 @@ NetworkTask::~NetworkTask()
void NetworkTask::run()
{
const auto &timeout = this->data_->timeout;
if (timeout.has_value())
{
this->timer_ = new QTimer(this);
this->timer_->setSingleShot(true);
this->timer_->start(timeout.value());
QObject::connect(this->timer_, &QTimer::timeout, this,
&NetworkTask::timeout);
}
this->reply_ = this->createReply();
if (!this->reply_)
{
this->deleteLater();
return;
}
const auto &timeout = this->data_->timeout;
if (timeout.has_value())
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
QObject::connect(this->reply_, &QNetworkReply::requestSent, this,
[this]() {
const auto &timeout = this->data_->timeout;
this->timer_ = new QTimer(this);
this->timer_->setSingleShot(true);
this->timer_->start(timeout.value());
QObject::connect(this->timer_, &QTimer::timeout,
this, &NetworkTask::timeout);
});
#else
this->timer_ = new QTimer(this);
this->timer_->setSingleShot(true);
this->timer_->start(timeout.value());
QObject::connect(this->timer_, &QTimer::timeout, this,
&NetworkTask::timeout);
#endif
}
QObject::connect(this->reply_, &QNetworkReply::finished, this,
&NetworkTask::finished);
}