I have an entry in my log viewer tree with no display name, (and as such no accountPtr which is causing a crash when clicked). Output from program when running is: QSortFilterProxyModel: invalid inserted rows reported by source model
FRom the code: if (newEntries.size() > 0) { Q_FOREACH(const Tpl::EntityPtr &entity, newEntries) { EntityModelItem *parent = m_rootItem->item(pendingEntities->account()); if (!parent) { beginInsertRows(QModelIndex(), m_rootItem->itemCount(), m_rootItem->itemCount()); parent = new EntityModelItem(m_rootItem); parent->setData(QVariant::fromValue(pendingEntities->account()), EntityModel::AccountRole); m_rootItem->addItem(parent); endInsertRows(); } QModelIndex parentIndex = index(parent->row(), 0, QModelIndex()); beginInsertRows(parentIndex, m_rootItem->item(parentIndex.row())->row(), m_rootItem->item(parentIndex.row())->row() + 1); EntityModelItem *item = new EntityModelItem(parent); item->setData(QVariant::fromValue(pendingEntities->account()), EntityModel::AccountRole); item->setData(QVariant::fromValue(entity), EntityModel::EntityRole); parent->addItem(item); if (pendingEntities->account()->connection()) { Tp::PendingOperation *op = pendingEntities->account()->connection()->contactManager()->contactsForIdentifiers( QStringList() << entity->identifier()); connect(op, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(onEntityContactRetrieved(Tp::PendingOperation*))); } } endInsertRows(); } } these beginInsertRows and endInsertRows doe not line up. if there are many entities being inserted, beginInsert is called many times, endInsert only once.
Are the calls actually being queued up? Because I'd assume that endInsert() simply ends all inserting operations, ie. signaling the view "I'm done with inserting, do your stuff now".
(In reply to comment #2) > Are the calls actually being queued up? Because I'd assume that endInsert() > simply ends all inserting operations, ie. signaling the view "I'm done with > inserting, do your stuff now". The Qt documentation is not completely clear about this, but I assume they want the calls to be paired: "An insertRows() implementation must call beginInsertRows() before inserting new rows into the data structure, and endInsertRows() immediately afterwards." d_ed already fixed this in git [0], but the "invalid inserted rows reported by source model" error is still there. [0] http://quickgit.kde.org/index.php?p=ktp-text-ui.git&a=commit&h=7de1e05aa6bf9a7ec7636ac50b8680b0b4345f3c
There is something called QModelTest which may be useful here.
Git commit bca67be2b9d31416ba3ef6b2b56e09fd0379a8f8 by Dan Vrátil. Committed on 15/07/2012 at 18:38. Pushed by dvratil into branch 'master'. Fix EntityModel warnings REVIEW: 105579 M +22 -26 logviewer/entity-model.cpp http://commits.kde.org/telepathy-text-ui/bca67be2b9d31416ba3ef6b2b56e09fd0379a8f8