diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index a77b2d57387..0f3e8672d8b 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -1241,15 +1241,15 @@ void WatchHandler::insertItem(WatchItem *item) void WatchModel::insertItem(WatchItem *item) { - WatchItem *existing = findItem(item->iname); - if (existing) + WatchItem *parent = findItem(parentName(item->iname)); + QTC_ASSERT(parent, return); + + if (WatchItem *existing = parent->findItem(item->iname)) removeItem(existing); //item->walkTree([item](TreeItem *sub) { sub->sortChildren(&watchItemSorter); }); item->sortChildren(&watchItemSorter); - WatchItem *parent = findItem(parentName(item->iname)); - QTC_ASSERT(parent, return); const int row = findInsertPosition(parent->children(), item); parent->insertChild(row, item);