Hello,
I'm testing my model with qt modeltest but two tests fail: rowsInserted and rowsRemoved.
This is the method to delete an item:
void UserModel
::delItem(const QString &nick
) {
int row = findItem(nick);
qDebug() << "Going to remove " << nick;
if(row < 0) {
qDebug() << "No item found with nick " << nick;
return;
}
UserItem *u = userList[row];
qDebug() << "Item " << u->nick << " removed";
userList.removeAt(row);
delete u;
qDebug() << "Really removed? " << (findUser(nick) < 0 ? "Yes" : "No!");
endRemoveRows();
}
void UserModel::delItem(const QString &nick)
{
int row = findItem(nick);
qDebug() << "Going to remove " << nick;
if(row < 0) {
qDebug() << "No item found with nick " << nick;
return;
}
UserItem *u = userList[row];
beginRemoveRows(QModelIndex(), row, row);
qDebug() << "Item " << u->nick << " removed";
userList.removeAt(row);
delete u;
qDebug() << "Really removed? " << (findUser(nick) < 0 ? "Yes" : "No!");
endRemoveRows();
}
To copy to clipboard, switch view to plain text mode
I have added more debug to modeltest.cpp and here the result:
Going to remove "foobar"
User "foobar" removed
Really removed? Yes
rowsRemoved start= 41 end= 41 oldsize= 192 parent= "" current rowcount= 192
isIndexValid No
itemWasRemoved: QVariant(, )
ASSERT: "c.oldSize - (end - start + 1) == model->rowCount(parent)" in file ./modeltest/modeltest.cpp, line 537
The item is really removed from userList (QList<UserItem *>) but the value returned by rowCount() doesn't reflect the change. rowCount() implementaion is ok:
int UserModel
::rowCount(const QModelIndex &parent
) const {
return parent.isValid() ? 0 : userList.count();
}
int UserModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : userList.count();
}
To copy to clipboard, switch view to plain text mode
Any idea? Thx
Bookmarks