diff --git a/src/libs/utils/treemodel.cpp b/src/libs/utils/treemodel.cpp index fbbb31c1c9c..7597ced6f67 100644 --- a/src/libs/utils/treemodel.cpp +++ b/src/libs/utils/treemodel.cpp @@ -713,9 +713,21 @@ void TreeItem::removeChildren() void TreeItem::sortChildren(const std::function &cmp) { if (m_model) { - m_model->layoutAboutToBeChanged(); - std::sort(m_children.begin(), m_children.end(), cmp); - m_model->layoutChanged(); + if (const int n = rowCount()) { + QVector tmp = m_children; + std::sort(tmp.begin(), tmp.end(), cmp); + if (tmp == m_children) { + // Nothing changed. + } else { + QModelIndex idx = index(); + m_model->beginRemoveRows(idx, 0, n - 1); + m_children.clear(); + m_model->endRemoveRows(); + m_model->beginInsertRows(idx, 0, n - 1); + tmp.swap(m_children); + m_model->endInsertRows(); + } + } } else { std::sort(m_children.begin(), m_children.end(), cmp); }