summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtreewidget
diff options
context:
space:
mode:
authorMarkku Heikkila <markku.heikkila@digia.com>2012-01-27 11:53:09 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-02-01 14:32:07 (GMT)
commit4f388c383e39b598d997e21bd9a4f16d89bd0625 (patch)
treead810f35e118a8222a850350bfd9d5f085a6febf /tests/auto/qtreewidget
parent9ad459913c8a277f3a6fbc7ee50937f126fe87ef (diff)
downloadQt-4f388c383e39b598d997e21bd9a4f16d89bd0625.zip
Qt-4f388c383e39b598d997e21bd9a4f16d89bd0625.tar.gz
Qt-4f388c383e39b598d997e21bd9a4f16d89bd0625.tar.bz2
Fix crash in QTreeWidgetItem::sortChildren when adding new item.
Recursive call is caused if user code calls QtreeWidgetItem()::sortChildren and sorting is enbled in QTreeWidget. First call is from user code and second is caused by timer. When timer expires second call is made. This recursion is prevented with QTreeModel::SkipSorting skipSorting() in QTreeWidgetItem::sortChildren(); Task-number: QTBUG-20345 Change-Id: I48af98b03c0291de8da90d1581bc55cc89846b8c Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto/qtreewidget')
-rw-r--r--tests/auto/qtreewidget/tst_qtreewidget.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qtreewidget/tst_qtreewidget.cpp b/tests/auto/qtreewidget/tst_qtreewidget.cpp
index e8a1de3..4957e3c 100644
--- a/tests/auto/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/qtreewidget/tst_qtreewidget.cpp
@@ -172,6 +172,7 @@ private slots:
void taskQTBUG2844_visualItemRect();
void setChildIndicatorPolicy();
+ void task20345_sortChildren();
public slots:
void itemSelectionChanged();
@@ -3366,7 +3367,38 @@ void tst_QTreeWidget::setChildIndicatorPolicy()
QTRY_COMPARE(delegate.numPaints, 1);
}
+void tst_QTreeWidget::task20345_sortChildren()
+{
+ // This test case is considered successful if it is executed (no crash in sorting)
+ QTreeWidget tw;
+ tw.setColumnCount(3);
+ tw.headerItem()->setText(0, "Col 0");
+ tw.headerItem()->setText(1, "Col 1");
+ tw.header()->setSortIndicator(0, Qt::AscendingOrder);
+ tw.setSortingEnabled(true);
+ tw.show();
+
+ QTreeWidgetItem *rootItem = 0;
+ QTreeWidgetItem *childItem = 0;
+ rootItem = new QTreeWidgetItem(&tw, QStringList("a"));
+ childItem = new QTreeWidgetItem(rootItem);
+ childItem->setText(1, "3");
+ childItem = new QTreeWidgetItem(rootItem);
+ childItem->setText(1, "1");
+ childItem = new QTreeWidgetItem(rootItem);
+ childItem->setText(1, "2");
+
+ tw.setCurrentItem(tw.topLevelItem(0));
+
+ QTreeWidgetItem * curItem = tw.currentItem();
+ int childCount = curItem->childCount() + 1;
+
+ QTreeWidgetItem * newItem = new QTreeWidgetItem(curItem);
+ newItem->setText(1, QString::number(childCount));
+ rootItem->sortChildren(1, Qt::AscendingOrder);
+ QVERIFY(1);
+}
QTEST_MAIN(tst_QTreeWidget)
#include "tst_qtreewidget.moc"