QmlDesigner: Fix deletion of connections

Since we have multiple instances of this class we cannot use
a static variable. We have to use a member instead.

Task-number: QDS-14451
Change-Id: Ia85c145fb0b8a491132ca270cb62fb75809a03a0
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
(cherry picked from commit 8800e041d2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thomas Hartmann
2025-03-19 15:42:04 +01:00
parent 188a5324d1
commit 6304f9f173
2 changed files with 8 additions and 4 deletions

View File

@@ -393,13 +393,16 @@ ToolBarBackend::ToolBarBackend(QObject *parent)
&ToolBarBackend::documentIndexChanged);
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, this, [this] {
static QMetaObject::Connection lastConnection;
disconnect(lastConnection);
disconnect(m_documentConnection);
if (auto textDocument = qobject_cast<TextEditor::TextDocument *>(
Core::EditorManager::currentDocument())) {
lastConnection = connect(textDocument->document(), &QTextDocument::modificationChanged,
this, &ToolBarBackend::isDocumentDirtyChanged);
m_documentConnection = connect(textDocument->document(),
&QTextDocument::modificationChanged,
this,
&ToolBarBackend::isDocumentDirtyChanged);
emit isDocumentDirtyChanged();
}
});

View File

@@ -235,6 +235,7 @@ private:
QStringList m_openDocuments;
QMetaObject::Connection m_kitConnection;
QMetaObject::Connection m_documentConnection;
};
} // namespace QmlDesigner