From 12d346a2c90dbf587fe32cbc2f206423fcd19ba2 Mon Sep 17 00:00:00 2001 From: Yixue Wang Date: Mon, 8 Jan 2024 15:29:42 +0800 Subject: [PATCH] fix: cross-thread parenting failure Cannot create a child in another thread. Do not use object tree, use QScopedPointer to manage life scope. Log: fix cross-thread parenting failure --- plugins/notification/notification.cpp | 2 +- plugins/notification/notification.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/notification/notification.cpp b/plugins/notification/notification.cpp index 157d1cc86..d51939c78 100644 --- a/plugins/notification/notification.cpp +++ b/plugins/notification/notification.cpp @@ -29,7 +29,7 @@ Notification::Notification(QWidget *parent) setMinimumSize(PLUGIN_BACKGROUND_MIN_SIZE, PLUGIN_BACKGROUND_MIN_SIZE); connect(this, &Notification::dndModeChanged, this, &Notification::refreshIcon); QtConcurrent::run([this](){ - m_dbus = new QDBusInterface("org.deepin.dde.Notification1", "/org/deepin/dde/Notification1", "org.deepin.dde.Notification1", QDBusConnection::sessionBus(), this); + m_dbus.reset(new QDBusInterface("org.deepin.dde.Notification1", "/org/deepin/dde/Notification1", "org.deepin.dde.Notification1")); // Refresh icon for the first time, cause org.deepin.dde.Notification1 might depend on dock's DBus, // we should not call org.deepin.dde.Notification1 in the main thread before dock's dbus is initialized. // Just refresh icon in the other thread. diff --git a/plugins/notification/notification.h b/plugins/notification/notification.h index 9a7970aee..02722fe1c 100644 --- a/plugins/notification/notification.h +++ b/plugins/notification/notification.h @@ -37,7 +37,7 @@ protected: private: QIcon m_icon; - QDBusInterface *m_dbus; + QScopedPointer m_dbus; bool m_dndMode; };