From e95495142321fdf5c3a50a7ff6322a711be68555 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 31 Dec 2017 12:38:33 +0100 Subject: Fix QAbstractItemModel::beginRemoveRows in examples QAbstractItemModel::beginRemoveRows() must not take a negative value for first or last. It will assert so we should make sure the examples are correct. The assertion was added in 00c09e752ff7e482e1308e0e34721dc979204595 Change-Id: I539175c0597ed6f0ae76b7493fd3dca40638714e Reviewed-by: Giuseppe D'Angelo Reviewed-by: Martin Smith --- examples/widgets/itemviews/puzzle/piecesmodel.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'examples/widgets/itemviews/puzzle/piecesmodel.cpp') diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.cpp b/examples/widgets/itemviews/puzzle/piecesmodel.cpp index f0649d3776..28b46836f4 100644 --- a/examples/widgets/itemviews/puzzle/piecesmodel.cpp +++ b/examples/widgets/itemviews/puzzle/piecesmodel.cpp @@ -203,10 +203,12 @@ Qt::DropActions PiecesModel::supportedDropActions() const void PiecesModel::addPieces(const QPixmap& pixmap) { - beginRemoveRows(QModelIndex(), 0, 24); - pixmaps.clear(); - locations.clear(); - endRemoveRows(); + if (!pixmaps.isEmpty()) { + beginRemoveRows(QModelIndex(), 0, pixmaps.size() - 1); + pixmaps.clear(); + locations.clear(); + endRemoveRows(); + } for (int y = 0; y < 5; ++y) { for (int x = 0; x < 5; ++x) { QPixmap pieceImage = pixmap.copy(x*m_PieceSize, y*m_PieceSize, m_PieceSize, m_PieceSize); -- cgit v1.2.3