fixed deleting QTimer on wrong thread

This commit is contained in:
fourtf
2019-08-20 23:30:39 +02:00
parent 14222f84f2
commit 7643c0d20d
16 changed files with 64 additions and 59 deletions
+10 -5
View File
@@ -16,12 +16,17 @@
namespace chatterino {
NetworkData::NetworkData()
: timer_(new QTimer())
{
timer_->setSingleShot(true);
DebugCount::increase("NetworkData");
}
NetworkData::~NetworkData()
{
this->timer_->deleteLater();
DebugCount::decrease("NetworkData");
}
@@ -75,8 +80,8 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
if (data->hasTimeout_)
{
data->timer_.setSingleShot(true);
data->timer_.start();
data->timer_->setSingleShot(true);
data->timer_->start();
}
auto onUrlRequested = [data, worker]() mutable {
@@ -106,9 +111,9 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
return;
}
if (data->timer_.isActive())
if (data->timer_->isActive())
{
QObject::connect(&data->timer_, &QTimer::timeout, worker,
QObject::connect(data->timer_, &QTimer::timeout, worker,
[reply, data]() {
log("Aborted!");
reply->abort();
@@ -228,7 +233,7 @@ void loadCached(const std::shared_ptr<NetworkData> &data)
});
}
}
} // namespace chatterino
}
}
void load(const std::shared_ptr<NetworkData> &data)
+1 -1
View File
@@ -51,7 +51,7 @@ struct NetworkData {
// to enable the timer, the "setTimeout" function needs to be called before
// execute is called
bool hasTimeout_{};
QTimer timer_;
QTimer *timer_;
QString getHash();
+8 -5
View File
@@ -50,11 +50,14 @@ NetworkRequest NetworkRequest::type(NetworkRequestType newRequestType) &&
NetworkRequest NetworkRequest::caller(const QObject *caller) &&
{
// Caller must be in gui thread
assert(caller->thread() == qApp->thread());
if (caller)
{
// Caller must be in gui thread
assert(caller->thread() == qApp->thread());
this->data->caller_ = const_cast<QObject *>(caller);
this->data->hasCaller_ = true;
this->data->caller_ = const_cast<QObject *>(caller);
this->data->hasCaller_ = true;
}
return std::move(*this);
}
@@ -100,7 +103,7 @@ NetworkRequest NetworkRequest::header(const char *headerName,
NetworkRequest NetworkRequest::timeout(int ms) &&
{
this->data->hasTimeout_ = true;
this->data->timer_.setInterval(ms);
this->data->timer_->setInterval(ms);
return std::move(*this);
}