From 0e2738b246569f269424ebcb0170f8c553facc19 Mon Sep 17 00:00:00 2001 From: Beat Hangartner Date: Fri, 9 Oct 2026 00:40:06 +0200 Subject: [PATCH] Stop listening to its children before the template editor is destroyed Closing a title block template editor crashed it. The editor deletes itself on close; QWidget's destructor then deletes its children, and some of them signal the editor as they go: - the scene deselects its cells, so the view emits selectedCellsChanged() to the editor's slot of the same name (when a cell was selected); - the undo stack is cleared, so it emits cleanChanged() to updateEditorTitle() (when the template was edited). Both slots then run on an object whose destructor has already run. A Debug build aborts ("Called object is not of the correct type (class destructor may have already run)"); a release build calls a member function of a destroyed object. Disconnect every child of the editor from it in the editor's destructor, before the base destructors delete the children. No file-format change, no change while the editor is open. Tests: none automated; the editor needs the whole application. Checked by hand (see the PR). Co-Authored-By: Claude Opus 5.5 Signed-off-by: Beat Hangartner --- sources/titleblock/qettemplateeditor.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index ec3f922da..c23a6fdd0 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -55,7 +55,17 @@ QETTitleBlockTemplateEditor::QETTitleBlockTemplateEditor(QWidget *parent) : Destructor */ QETTitleBlockTemplateEditor::~QETTitleBlockTemplateEditor() -{} +{ + // QWidget's destructor deletes the children, and some of them + // signal this editor as they go: the scene deselects its cells (the + // view emits selectedCellsChanged()), the undo stack is cleared + // (cleanChanged()). By then this editor is already destroyed, so + // stop listening to all of its children first. + const auto children = findChildren(); + for (QObject *child : children) { + disconnect(child, nullptr, this, nullptr); + } +} /** @return the location of the currently edited template