summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-02-28 03:15:19 (GMT)
committerMartin Jones <martin.jones@nokia.com>2011-02-28 03:29:29 (GMT)
commit6d7c12ae3f3d0eae6946524ce023ac452cf188c4 (patch)
tree8d8ecc56ba1600e0b34675c7f3661c7002505e93
parent39013a4a8238d522ed1d13adb25e702da9e25fc9 (diff)
downloadQt-6d7c12ae3f3d0eae6946524ce023ac452cf188c4.zip
Qt-6d7c12ae3f3d0eae6946524ce023ac452cf188c4.tar.gz
Qt-6d7c12ae3f3d0eae6946524ce023ac452cf188c4.tar.bz2
FolderListModel emitted incorrect rowsRemoved range causing crash.
beginRemoveRows() takes the first and last index as parameters, but it was passing count rather than count-1 as the last index. Change-Id: I81a6fbf085acacf5f8c1ca847b0bdc826bcf405b Task-number: QTBUG-17775 Reviewed-by: Bea Lam
-rw-r--r--src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp31
2 files changed, 31 insertions, 2 deletions
diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp
index d5726c1..9fe01bf 100644
--- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp
+++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp
@@ -365,7 +365,7 @@ void QDeclarativeFolderListModel::refresh()
{
d->folderIndex = QModelIndex();
if (d->count) {
- emit beginRemoveRows(QModelIndex(), 0, d->count);
+ emit beginRemoveRows(QModelIndex(), 0, d->count-1);
d->count = 0;
emit endRemoveRows();
}
diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp b/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp
index a62ea31..6028333 100644
--- a/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp
@@ -62,14 +62,24 @@ class tst_qdeclarativefolderlistmodel : public QObject
{
Q_OBJECT
public:
- tst_qdeclarativefolderlistmodel() {}
+ tst_qdeclarativefolderlistmodel() : removeStart(0), removeEnd(0) {}
+
+public slots:
+ void removed(const QModelIndex &, int start, int end) {
+ removeStart = start;
+ removeEnd = end;
+ }
private slots:
void basicProperties();
+ void refresh();
private:
void checkNoErrors(const QDeclarativeComponent& component);
QDeclarativeEngine engine;
+
+ int removeStart;
+ int removeEnd;
};
void tst_qdeclarativefolderlistmodel::checkNoErrors(const QDeclarativeComponent& component)
@@ -115,6 +125,25 @@ void tst_qdeclarativefolderlistmodel::basicProperties()
QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile(""));
}
+void tst_qdeclarativefolderlistmodel::refresh()
+{
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/basic.qml"));
+ checkNoErrors(component);
+
+ QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create());
+ QVERIFY(flm != 0);
+
+ int count = flm->rowCount();
+
+ connect(flm, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
+ this, SLOT(removed(const QModelIndex&,int,int)));
+
+ flm->setProperty("sortReversed", true);
+
+ QCOMPARE(removeStart, 0);
+ QCOMPARE(removeEnd, count-1);
+}
+
QTEST_MAIN(tst_qdeclarativefolderlistmodel)
#include "tst_qdeclarativefolderlistmodel.moc"