[utilities/krusader] app/Panel: Panel: Fix a premature destruction
Toni Asensi Esteve <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 5ca2a1e548902d0fd293233e850904a6147ff2fb by Toni Asensi Esteve.
Committed on 16/08/2026 at 22:14.
Pushed by asensi into branch 'master'.
Panel: Fix a premature destruction
Fix a premature destruction / dangling pointer by creating a KrPreviewPopup
on the heap (otherwise, the stack object is destroyed at the end of
the `if` block, before the menu is shown).
Revision: https://invent.kde.org/utilities/krusader/-/merge_requests/193
M +3 -2 app/Panel/krpreviewpopup.cpp
M +1 -1 app/Panel/krpreviewpopup.h
M +3 -3 app/Panel/panelcontextmenu.cpp
https://invent.kde.org/utilities/krusader/-/commit/5ca2a1e548902d0fd293233e850904a6147ff2fb
diff --git a/app/Panel/krpreviewpopup.cpp b/app/Panel/krpreviewpopup.cpp
index dd73c95d5..1877f3d12 100644
--- a/app/Panel/krpreviewpopup.cpp
+++ b/app/Panel/krpreviewpopup.cpp
@@ -80,8 +80,9 @@ public:
}
};
-KrPreviewPopup::KrPreviewPopup()
- : jobStarted(false)
+KrPreviewPopup::KrPreviewPopup(QWidget *parent)
+ : QMenu(parent)
+ , jobStarted(false)
{
prevNotAvailAction = addAction(i18n("Preview not available"));
diff --git a/app/Panel/krpreviewpopup.h b/app/Panel/krpreviewpopup.h
index 9bd8914a7..49e53b712 100644
--- a/app/Panel/krpreviewpopup.h
+++ b/app/Panel/krpreviewpopup.h
@@ -23,7 +23,7 @@ class KrPreviewPopup : public QMenu
Q_OBJECT
public:
- KrPreviewPopup();
+ explicit KrPreviewPopup(QWidget *parent);
void setUrls(const QList<QUrl> &urls);
public slots:
diff --git a/app/Panel/panelcontextmenu.cpp b/app/Panel/panelcontextmenu.cpp
index 6cd46338c..a3ef10cdb 100644
--- a/app/Panel/panelcontextmenu.cpp
+++ b/app/Panel/panelcontextmenu.cpp
@@ -128,9 +128,9 @@ PanelContextMenu::PanelContextMenu(KrPanel *krPanel, QWidget *parent)
// ------------- Preview - local filesystem only ?
if (panel->func->files()->isLocal()) {
// create the preview popup
- KrPreviewPopup preview;
- preview.setUrls(panel->func->files()->getUrls(fileNames));
- QAction *previewAction = addMenu(&preview);
+ KrPreviewPopup *preview = new KrPreviewPopup(this);
+ preview->setUrls(panel->func->files()->getUrls(fileNames));
+ QAction *previewAction = addMenu(preview);
previewAction->setData(QVariant(static_cast<int>(PREVIEW_ID)));
previewAction->setText(i18n("Preview"));
previewAction->setIcon(Icon("document-print-preview"));