From 7512b92a3614b3fcde4a9e801039e1fed052ea0d Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Thu, 27 Jul 2023 15:09:14 +0300 Subject: [PATCH] Fix crash on application exit (Qt 6.5) PR #19169. --- src/app/signalhandler.cpp | 3 ++- src/base/torrentfileswatcher.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/signalhandler.cpp b/src/app/signalhandler.cpp index 36d24bcec..be70f254d 100644 --- a/src/app/signalhandler.cpp +++ b/src/app/signalhandler.cpp @@ -43,6 +43,7 @@ #endif #include +#include #include "base/version.h" @@ -89,7 +90,7 @@ namespace const char *msgs[] = {"Catching signal: ", sysSigName[signum], "\nExiting cleanly\n"}; std::for_each(std::begin(msgs), std::end(msgs), safePrint); signal(signum, SIG_DFL); - QCoreApplication::exit(); // unsafe, but exit anyway + QMetaObject::invokeMethod(qApp, [] { QCoreApplication::exit(); }, Qt::QueuedConnection); // unsafe, but exit anyway } #ifdef STACKTRACE diff --git a/src/base/torrentfileswatcher.cpp b/src/base/torrentfileswatcher.cpp index 7015a293d..6a84f58b9 100644 --- a/src/base/torrentfileswatcher.cpp +++ b/src/base/torrentfileswatcher.cpp @@ -141,7 +141,7 @@ TorrentFilesWatcher *TorrentFilesWatcher::instance() } TorrentFilesWatcher::TorrentFilesWatcher(QObject *parent) - : QObject {parent} + : QObject(parent) , m_ioThread {new QThread} { const auto *btSession = BitTorrent::Session::instance(); @@ -163,7 +163,7 @@ void TorrentFilesWatcher::initWorker() connect(m_asyncWorker, &TorrentFilesWatcher::Worker::torrentFound, this, &TorrentFilesWatcher::onTorrentFound); m_asyncWorker->moveToThread(m_ioThread.get()); - connect(m_ioThread.get(), &QThread::finished, m_asyncWorker, &QObject::deleteLater); + connect(m_ioThread.get(), &QThread::finished, this, [this] { delete m_asyncWorker; }); m_ioThread->start(); for (auto it = m_watchedFolders.cbegin(); it != m_watchedFolders.cend(); ++it)