Hi!
I just added the modeltest code to my project and indeed it finds problems in my code. Now, I was pretty sure I had followed the HOWTO in the docs very closely (f.e. [0]) when I created my first model a few months back, so I now wonder how relevant certain assertions are in real life, i.e. will they ever make problems if certain reimplemented methods like data(), index() aso. are called from other parts of the Interview architecture?
One certain assertion is the test if negative column/row numbers are correctly handled in QWhateverModel::index(). The relevant code in [0] for this is
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
const
{
TreeItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<TreeItem*>(parent.internalPointer());
TreeItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
Now since there are no checks for row < 0 or column < 0 I wonder why createIndex returns an invalid index here on purpose? Or maybe, one should fix up this example =)
Thomas.
[0] http://doc.trolltech.com/4.2/itemviews-simpletreemodel.html