From e1fe84cb8a16e4ea9425f1f6533dc75afe2fd4c4 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 6 Aug 2009 13:54:58 +0200 Subject: QStandardItem::takeRow() would crash when it had no columns. Reviewed-by: olivier --- src/gui/itemviews/qstandarditemmodel.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gui/itemviews/qstandarditemmodel.cpp b/src/gui/itemviews/qstandarditemmodel.cpp index e71d8f9..6f99fb5 100644 --- a/src/gui/itemviews/qstandarditemmodel.cpp +++ b/src/gui/itemviews/qstandarditemmodel.cpp @@ -1745,15 +1745,17 @@ QList QStandardItem::takeRow(int row) if (d->model) d->model->d_func()->rowsAboutToBeRemoved(this, row, row); QList items; - int index = d->childIndex(row, 0); - int col_count = d->columnCount(); - for (int column = 0; column < col_count; ++column) { - QStandardItem *ch = d->children.at(index + column); - if (ch) - ch->d_func()->setParentAndModel(0, 0); - items.append(ch); + int index = d->childIndex(row, 0); // Will return -1 if there are no columns + if (index != -1) { + int col_count = d->columnCount(); + for (int column = 0; column < col_count; ++column) { + QStandardItem *ch = d->children.at(index + column); + if (ch) + ch->d_func()->setParentAndModel(0, 0); + items.append(ch); + } + d->children.remove(index, col_count); } - d->children.remove(index, col_count); d->rows--; if (d->model) d->model->d_func()->rowsRemoved(this, row, 1); -- cgit v0.12