From f6d57999d80c04f930916197806e3cd47b88d81c Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 9 Dec 2024 14:40:04 +0100 Subject: [PATCH] OpenEditorsWindow: Fix crash when entries are removed behind the back of the window. The open editors window (that appears on ctrl+tab / opt+tab) keeps pointers to Entry items from the DocumentModel. Usually that is no problem, because the editor manager hides the open editors window before closing editors. But there was an issue with suspended entries, that can be reproduced with some effort, e.g. - Give e.g. "Unload/Close Project" a shortcut that you can trigger while the popup is open, like Opt+K on macOS, or Ctrl+Shift+J on Lin/Win - Open a project and a few files from the project - Switch the document switcher of the editor view to "" - Close & reopen QtC, reload the session - You should now have a few "suspended" documents, and *only* suspended documents, since the editor view doesn't show anything - Open the open editors window with ctrl+tab / opt+tab and trigger the "close project" shortcut without closing the popup - The documents and the project close, but the popup is open and shows the old items - The moment you press e.g. tab again to interact with the popup, it crashes Just close the popup if items are removed from the document model "behind its back". Also clear all items whenever it is set invisible so we don't have references to broken items hanging around. Change-Id: I70853838f292235efea0561755b35c20aaa8473d Reviewed-by: David Schulz --- src/plugins/coreplugin/editormanager/openeditorswindow.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/plugins/coreplugin/editormanager/openeditorswindow.cpp b/src/plugins/coreplugin/editormanager/openeditorswindow.cpp index 519d0ff954c..70dc13d2bd3 100644 --- a/src/plugins/coreplugin/editormanager/openeditorswindow.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorswindow.cpp @@ -146,6 +146,11 @@ OpenEditorsWindow::OpenEditorsWindow(QWidget *parent) auto layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(m_editorView); + + // Close the popup and clear it if documents are closed behind the back of the view + connect(DocumentModel::model(), &QAbstractItemModel::rowsAboutToBeRemoved, this, [this] { + setVisible(false); + }); } void OpenEditorsWindow::selectAndHide() @@ -159,6 +164,8 @@ void OpenEditorsWindow::setVisible(bool visible) QWidget::setVisible(visible); if (visible) setFocus(); + else + m_editorView->m_model.clear(); } bool OpenEditorsWindow::eventFilter(QObject *obj, QEvent *e)