path: root/src
diff options
authorGiuseppe D'Angelo <>2017-09-18 00:41:20 +0200
committerGiuseppe D'Angelo <>2017-11-30 13:01:45 +0000
commitbdcbbd7d5ba41ef3aeb24c12ef22ad2fdb7aac90 (patch)
tree905b7aab20ecf96617c1365f976aae52616b2c8d /src
parentc35342ffeba10deecb2d8c0ce30a3a1a4ec1ee8d (diff)
QTreeWidgetItem::insertChildren: ignore out of bounds indexes
QTreeWidgetItem::insertChildren should behave like a more-optimized QTreeWidgetItem::insertChild. Unlike the latter, the former lacks out-of-bounds checks, resulting in successful insertions even when using an invalid index (say, bigger than the row/column count). Reintroduce some sanity checks instead. This allows to fix a "fixme" left in the autotest. [ChangeLog][QtWidgets][QTreeWidgetItem] QTreeWidgetItem::insertChildren now ignores insertions happening at invalid indices, for consistency with QTreeWidgetItem::insertChild. Change-Id: I1532597768cc6aff96a6e8f356bc6075b582801d Reviewed-by: Thorbjørn Lund Martsum <>
Diffstat (limited to 'src')
1 files changed, 3 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp
index 601ed44b55..334a3e0c75 100644
--- a/src/widgets/itemviews/qtreewidget.cpp
+++ b/src/widgets/itemviews/qtreewidget.cpp
@@ -2009,6 +2009,9 @@ void QTreeWidgetItem::addChildren(const QList<QTreeWidgetItem*> &children)
void QTreeWidgetItem::insertChildren(int index, const QList<QTreeWidgetItem*> &children)
+ if (index < 0 || index > this->children.count() || children.isEmpty())
+ return;
if (view && view->isSortingEnabled()) {
for (int n = 0; n < children.count(); ++n)