┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Englbrecht <[email protected]>2026-05-31 18:59:36 +0200
committerMéven Car <[email protected]>2026-06-01 09:04:16 +0000
commit44973c9dd016569e643a73148c32bd1a0b01d71d (patch)
tree4fc83d93e58eae08986bfcbdf00a10f0e17d5b3e
parentb860b18e2dc8d00dbb72fcfe210f4e48d53ec00c (diff)
dolphinmainwindow,dolphinview: clarify QPointer semantics around exec()
exec() runs a nested event loop that can destroy the parent widget, so the post-exec null-check on the QPointer is intentional, not redundant. dolphinmainwindow: replace `if (contextMenu) deleteLater()` with `delete contextMenu`. QPointer returns nullptr for a destroyed object, making delete a safe no-op. dolphinview: capture the menu as a raw pointer for pre-exec setup; reserve the QPointer for the post-exec liveness check and deletion.
-rw-r--r--src/dolphinmainwindow.cpp6
-rw-r--r--src/views/dolphinview.cpp17
2 files changed, 10 insertions, 13 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index 439db8293..c1bbcc5f5 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -1522,11 +1522,7 @@ void DolphinMainWindow::openContextMenu(const QPoint &pos, const KFileItem &item
{
QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, item, selectedItems, url, m_fileItemActions);
contextMenu->exec(pos);
-
- // Delete the menu, unless it has been deleted in its own nested event loop already.
- if (contextMenu) {
- contextMenu->deleteLater();
- }
+ delete contextMenu;
}
QMenu *DolphinMainWindow::createPopupMenu()
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 97c1e926c..6882df5d3 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -1281,6 +1281,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF &pos)
ViewProperties props(viewPropertiesUrl());
QPointer<QMenu> menu = new QMenu(this);
+ QMenu *const rawMenu = menu;
KItemListView *view = m_container->controller()->view();
const QList<QByteArray> visibleRolesSet = view->visibleRoles();
@@ -1305,11 +1306,11 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF &pos)
const QString text = m_model->roleDescription(info.role);
QAction *action = nullptr;
if (info.group.isEmpty()) {
- action = menu->addAction(text);
+ action = rawMenu->addAction(text);
} else {
if (!groupMenu || info.group != groupName) {
groupName = info.group;
- groupMenu = menu->addMenu(groupName);
+ groupMenu = rawMenu->addMenu(groupName);
}
action = groupMenu->addAction(text);
@@ -1324,26 +1325,26 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF &pos)
action->setEnabled(enable);
}
- menu->addSeparator();
+ rawMenu->addSeparator();
- QActionGroup *widthsGroup = new QActionGroup(menu);
+ QActionGroup *widthsGroup = new QActionGroup(rawMenu);
const bool autoColumnWidths = props.headerColumnWidths().isEmpty();
- QAction *toggleSidePaddingAction = menu->addAction(i18nc("@action:inmenu", "Side Padding"));
+ QAction *toggleSidePaddingAction = rawMenu->addAction(i18nc("@action:inmenu", "Side Padding"));
toggleSidePaddingAction->setCheckable(true);
toggleSidePaddingAction->setChecked(layoutDirection() == Qt::LeftToRight ? view->header()->leftPadding() > 0 : view->header()->rightPadding() > 0);
- QAction *autoAdjustWidthsAction = menu->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
+ QAction *autoAdjustWidthsAction = rawMenu->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
autoAdjustWidthsAction->setCheckable(true);
autoAdjustWidthsAction->setChecked(autoColumnWidths);
autoAdjustWidthsAction->setActionGroup(widthsGroup);
- QAction *customWidthsAction = menu->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
+ QAction *customWidthsAction = rawMenu->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
customWidthsAction->setCheckable(true);
customWidthsAction->setChecked(!autoColumnWidths);
customWidthsAction->setActionGroup(widthsGroup);
- QAction *action = menu->exec(pos.toPoint());
+ QAction *action = rawMenu->exec(pos.toPoint());
if (menu && action) {
KItemListHeader *header = view->header();