Skip to content

Commit

Permalink
fix: cross-thread parenting failure
Browse files Browse the repository at this point in the history
Cannot create a child in another thread. Do not use object tree, use
QScopedPointer to manage life scope.

Log: fix cross-thread parenting failure
  • Loading branch information
asterwyx committed Jan 8, 2024
1 parent 2a5a1e0 commit 80b2862
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/notification/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion plugins/notification/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private Q_SLOTS:

private:
QIcon m_icon;
QDBusInterface *m_dbus;
QScopedPointer<QDBusInterface> m_dbus;
bool m_dndMode;
};

Expand Down

0 comments on commit 80b2862

Please sign in to comment.