From 73339208cd3469e37eb0ef5555e3de5544cb0a8e Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 19 Nov 2018 10:07:27 +0100 Subject: [PATCH] [DBusMenuImporter] Don't call removeAction() to avoid an empty QMenu As soon as QMenu becomes empty it is closed. This can happen when the application completely reloads its menu. Instead, call deleteLater which will destroy the QAction later at which point it is automatically removed from the menu. BUG: 399975 FIXED-IN: 5.14.4 CHANGELOG: Fixed global menu misbehaving and unexpectedly closing with certain applications Differential Revision: https://phabricator.kde.org/D16297 --- libdbusmenuqt/dbusmenuimporter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libdbusmenuqt/dbusmenuimporter.cpp b/libdbusmenuqt/dbusmenuimporter.cpp index 1a883e334..9f7028b40 100644 --- a/libdbusmenuqt/dbusmenuimporter.cpp +++ b/libdbusmenuqt/dbusmenuimporter.cpp @@ -410,7 +410,9 @@ void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher) for (QAction *action: menu->actions()) { int id = action->property(DBUSMENU_PROPERTY_ID).toInt(); if (! newDBusMenuItemIds.contains(id)) { - menu->removeAction(action); + // Not calling removeAction() as QMenu will immediately close when it becomes empty, + // which can happen when an application completely reloads this menu. + // When the action is deleted deferred, it is removed from the menu. action->deleteLater(); d->m_actionForId.remove(id); }