From 94aeeed95fbed6bcc4dc5e89b633996d880f9f14 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 2 Apr 2019 15:14:00 +0800 Subject: [PATCH] Work around the crash occurred in QTimer See Qt commit: https://code.qt.io/cgit/qt/qtbase.git/commit/src/corelib/kernel/qtimer.cpp?id=a623fe8d2a60ff333d5779f877e3b20f0e141ff1 Fixes #9985. --- src/webui/api/synccontroller.cpp | 15 ++++++++++++--- src/webui/api/synccontroller.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/webui/api/synccontroller.cpp b/src/webui/api/synccontroller.cpp index 406cde859..f3f27090f 100644 --- a/src/webui/api/synccontroller.cpp +++ b/src/webui/api/synccontroller.cpp @@ -31,8 +31,8 @@ #include #include +#include #include -#include #include "base/bittorrent/peerinfo.h" #include "base/bittorrent/session.h" @@ -335,7 +335,7 @@ SyncController::SyncController(ISessionManager *sessionManager, QObject *parent) connect(m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, this, &SyncController::freeDiskSpaceSizeUpdated); m_freeDiskSpaceThread->start(); - QTimer::singleShot(0, m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check); + invokeChecker(); m_freeDiskSpaceElapsedTimer.start(); } @@ -521,7 +521,7 @@ void SyncController::torrentPeersAction() qint64 SyncController::getFreeDiskSpace() { if (m_freeDiskSpaceElapsedTimer.hasExpired(FREEDISKSPACE_CHECK_TIMEOUT)) { - QTimer::singleShot(0, m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check); + invokeChecker(); m_freeDiskSpaceElapsedTimer.restart(); } @@ -532,3 +532,12 @@ void SyncController::freeDiskSpaceSizeUpdated(qint64 freeSpaceSize) { m_freeDiskSpace = freeSpaceSize; } + +void SyncController::invokeChecker() const +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + QMetaObject::invokeMethod(m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check, Qt::QueuedConnection); +#else + QMetaObject::invokeMethod(m_freeDiskSpaceChecker, "check", Qt::QueuedConnection); +#endif +} diff --git a/src/webui/api/synccontroller.h b/src/webui/api/synccontroller.h index e6c48c669..35422478a 100644 --- a/src/webui/api/synccontroller.h +++ b/src/webui/api/synccontroller.h @@ -56,6 +56,7 @@ private slots: private: qint64 getFreeDiskSpace(); + void invokeChecker() const; qint64 m_freeDiskSpace = 0; FreeDiskSpaceChecker *m_freeDiskSpaceChecker = nullptr;