From 48ed8497ea29971c544414991200393a58dd8088 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 26 Jul 2023 06:52:02 +0200 Subject: [PATCH] use invoking when displaying messageboxes to avoid crashes when called directly from non-gui thread --- src/librssguard/miscellaneous/application.cpp | 25 +++++++++++++++---- src/librssguard/miscellaneous/application.h | 8 +++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index 7d28703aa..5b3f182a1 100644 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -670,11 +670,11 @@ void Application::deleteTrayIcon() { } } -void Application::showGuiMessage(Notification::Event event, - const GuiMessage& msg, - const GuiMessageDestination& dest, - const GuiAction& action, - QWidget* parent) { +void Application::showGuiMessageCore(Notification::Event event, + const GuiMessage& msg, + GuiMessageDestination dest, + const GuiAction& action, + QWidget* parent) { if (SystemTrayIcon::areNotificationsEnabled()) { auto notification = m_notifications->notificationForEvent(event); @@ -714,6 +714,21 @@ void Application::showGuiMessage(Notification::Event event, } } +void Application::showGuiMessage(Notification::Event event, + const GuiMessage& msg, + GuiMessageDestination dest, + const GuiAction& action, + QWidget* parent) { + QMetaObject::invokeMethod(this, + "showGuiMessageCore", + Qt::ConnectionType::QueuedConnection, + Q_ARG(Notification::Event, event), + Q_ARG(const GuiMessage&, msg), + Q_ARG(GuiMessageDestination, dest), + Q_ARG(const GuiAction&, action), + Q_ARG(QWidget*, parent)); +} + WebViewer* Application::createWebView() { #if !defined(USE_WEBENGINE) return new TextBrowserViewer(); diff --git a/src/librssguard/miscellaneous/application.h b/src/librssguard/miscellaneous/application.h index 0204dae1c..3e0994a2a 100644 --- a/src/librssguard/miscellaneous/application.h +++ b/src/librssguard/miscellaneous/application.h @@ -163,7 +163,7 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication { // or in message box if tray icon is disabled. void showGuiMessage(Notification::Event event, const GuiMessage& msg, - const GuiMessageDestination& dest = {}, + GuiMessageDestination dest = {}, const GuiAction& action = {}, QWidget* parent = nullptr); @@ -193,6 +193,12 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication { void displayLog(); + void showGuiMessageCore(Notification::Event event, + const GuiMessage& msg, + GuiMessageDestination dest = {}, + const GuiAction& action = {}, + QWidget* parent = nullptr); + private slots: void fillCmdArgumentsParser(QCommandLineParser& parser);