EditorManager: Update current editor prior to deleting other editors

Otherwise it may happen that destructor of an editor being
deleted may trigger a call to EditorManager::currentEditor()
before reaching the editor's QObject destructor. In this case
the pointer to the editor (EditorManagerPrivate::m_currentEditor)
isn't cleared yet by Qt and it may return the pointer to
partially destructed object.

Change-Id: I4f44dce8d680008148a73eb2a8ac13477d0fb825
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2021-07-13 12:33:32 +02:00
parent 425353aa16
commit 9cd97e940b

View File

@@ -1751,9 +1751,6 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
emit m_instance->editorsClosed(Utils::toList(acceptedEditors));
foreach (IEditor *editor, acceptedEditors)
delete editor;
if (focusView) {
activateView(focusView);
} else {
@@ -1761,6 +1758,9 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
setCurrentEditor(currentView->currentEditor());
}
foreach (IEditor *editor, acceptedEditors)
delete editor;
if (!EditorManager::currentEditor()) {
emit m_instance->currentEditorChanged(nullptr);
updateActions();