From 1a980008be43e006c21254c45a06b7dd17a215bd Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 18 May 2022 23:12:18 +0200 Subject: [PATCH] Fix crash while undoing with the menu on an empty annotation BUGS: 453987 --- part/annotwindow.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/part/annotwindow.cpp b/part/annotwindow.cpp index c446c0d11..de408292c 100644 --- a/part/annotwindow.cpp +++ b/part/annotwindow.cpp @@ -326,7 +326,16 @@ void AnnotWindow::slotUpdateUndoAndRedoInContextMenu(QMenu *menu) QList actionList = menu->actions(); enum { UndoAct, RedoAct, CutAct, CopyAct, PasteAct, ClearAct, SelectAllAct, NCountActs }; - QAction *kundo = KStandardAction::create(KStandardAction::Undo, m_document, SLOT(undo()), menu); + QAction *kundo = KStandardAction::create( + KStandardAction::Undo, + m_document, + [doc = m_document] { + // We need a QueuedConnection because undoing may end up destroying the menu this action is on + // because it will undo the addition of the annotation. If it's not queued things gets unhappy + // because the menu is destroyed in the middle of processing the click on the menu itself + QMetaObject::invokeMethod(doc, &Okular::Document::undo, Qt::QueuedConnection); + }, + menu); QAction *kredo = KStandardAction::create(KStandardAction::Redo, m_document, SLOT(redo()), menu); connect(m_document, &Okular::Document::canUndoChanged, kundo, &QAction::setEnabled); connect(m_document, &Okular::Document::canRedoChanged, kredo, &QAction::setEnabled);