QmlDesigner: Fix disconnecting the last connection

Amends b5aac705ea

Change-Id: I723b7d7847dfdb75d173a61b023e1fc30ea40eb4
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Jarek Kobus
2024-08-23 10:23:11 +02:00
parent d211208011
commit 34228039d8

View File

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