Skip to content

[PlasmaComponents MenuItem] Create dummy action when action gets destroyed

Kai Uwe Broulik requested to merge work/kbroulik/menuitemownershipcrash into master

MenuItem does not delete other people's QAction but it does not take kindly to the QAction being deleted under it. As a workaround recreate a dummy action when ours gets destroyed.

This crash can easily be triggered by opening the Media Controller applet and quickly right-clicking its icon to open the context menu. Media Controller recreates its actions in contextualActionsAboutToShow, which removes and deletes them. Then the Instantiator in System Tray's ExpandedRepresentation updates its model, deleting the delegate items (MenuItem instances) it created. This prompts the Menu to run removeMenuItem on the now removed MenuItem, accessing its backing action() to remove it from the menu, resulting in a crash as it was deleted earlier.


System Tray no longer crashes when I click media controller and immediately right-click it. Not really happy with this approach, though.

I also have no idea what the following code in MenuItem was supposed to do:

connect(this, &QObject::destroyed, this, &QMenuItem::deleteLater);

@mart @davidedmundson

Merge request reports

Loading