From e078d05f510a2dd77aafa7aed79d45cbcb247208 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Fri, 31 May 2024 16:17:10 +0200 Subject: [PATCH] Utils: Fix connection error When add / remove buttons are disabled, the connection fails. Change-Id: I6c9a3233f156b88e516481a6fc8e072ea5e1c13b Reviewed-by: David Schulz --- src/libs/utils/aspects.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index 25a21fb7397..bc233ed188a 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -2681,22 +2681,26 @@ void StringListAspect::addToLayout(Layout &parent) } }; - connect(add, &QPushButton::clicked, this, [this, populate, editor] { - d->undoable.setSilently(d->undoable.get() << ""); - populate(); - const QTreeWidgetItem *root = editor->invisibleRootItem(); - QTreeWidgetItem *lastChild = root->child(root->childCount() - 1); - const QModelIndex index = editor->indexFromItem(lastChild, 0); - editor->edit(index); - }); + if (add) { + connect(add, &QPushButton::clicked, this, [this, populate, editor] { + d->undoable.setSilently(d->undoable.get() << ""); + populate(); + const QTreeWidgetItem *root = editor->invisibleRootItem(); + QTreeWidgetItem *lastChild = root->child(root->childCount() - 1); + const QModelIndex index = editor->indexFromItem(lastChild, 0); + editor->edit(index); + }); + } - connect(remove, &QPushButton::clicked, this, [this, editor, itemsToStringList] { - const QList selected = editor->selectedItems(); - QTC_ASSERT(selected.size() == 1, return); - editor->invisibleRootItem()->removeChild(selected.first()); - delete selected.first(); - d->undoable.set(undoStack(), itemsToStringList()); - }); + if (remove) { + connect(remove, &QPushButton::clicked, this, [this, editor, itemsToStringList] { + const QList selected = editor->selectedItems(); + QTC_ASSERT(selected.size() == 1, return); + editor->invisibleRootItem()->removeChild(selected.first()); + delete selected.first(); + d->undoable.set(undoStack(), itemsToStringList()); + }); + } connect( &d->undoable.m_signal, &UndoSignaller::changed, editor, [this, populate, itemsToStringList] {