PDA

View Full Version : QAbstractItemModel question



zgulser
5th June 2012, 10:08
Hi,

The code following crashes sometimes. When I debugged the code, I saw that something went wrong in the layoutAboutToBeChanged() but couldn't figured it out. Am I missing something here?



void BuddyListModel::onProfileRefreshed(Contact* contact)
{
if(!_contacts.contains(contact))
{
return;
}

int row = _contacts.indexOf(contact);
QModelIndex contactIndex = index(row, 0, QModelIndex());

/* code crashes here sometimes */
Q_EMIT layoutAboutToBeChanged();
Q_EMIT dataChanged(contactIndex, contactIndex);
Q_EMIT layoutChanged();
/* end of crash zone */
}


Added after 1 18 minutes:

This is where the program crashes actually. "it" seems to be null. So in it.value(), it crashes.



inline QHash<QModelIndex, Mapping *>::const_iterator index_to_iterator(
const QModelIndex &proxy_index) const
{
Q_ASSERT(proxy_index.isValid());
Q_ASSERT(proxy_index.model() == q_func());
const void *p = proxy_index.internalPointer();
Q_ASSERT(p);
QHash<QModelIndex, Mapping *>::const_iterator it =
static_cast<const Mapping*>(p)->map_iter;
Q_ASSERT(it != source_index_mapping.constEnd());
Q_ASSERT(it.value());
return it;
}

zgulser
5th June 2012, 11:48
And finally this is the partial debug log..



QtGuid4.dll!QSortFilterProxyModelPrivate::index_to _iterator(const QModelIndex & proxy_index={...}) Line 174 + 0x8 bytes C++
QtGuid4.dll!QSortFilterProxyModelPrivate::proxy_to _source(const QModelIndex & proxy_index={...}) Line 350 C++
QtGuid4.dll!QSortFilterProxyModel::mapToSource(con st QModelIndex & proxyIndex={...}) Line 2483 + 0x10 bytes C++
QtGuid4.dll!QSortFilterProxyModelPrivate::store_pe rsistent_indexes() Line 977 + 0x18 bytes C++
QtGuid4.dll!QSortFilterProxyModelPrivate::_q_sourc eLayoutAboutToBeChanged() Line 1225 + 0xc bytes C++
QtGuid4.dll!QSortFilterProxyModel::qt_static_metac all(QObject * _o=0x05cae320, QMetaObject::Call _c=InvokeMetaMethod, int _id=9, void * * _a=0x001ebab4) Line 111 + 0xf bytes C++
QtCored4.dll!QMetaObject::activate(QObject * sender=0x05cadc48, const QMetaObject * m=0x66f18230, int local_signal_index=3, void * * argv=0x00000000) Line 3528 + 0x2e bytes C++
> QtCored4.dll!QAbstractItemModel::layoutAboutToBeCh anged() Line 183 + 0x12 bytes C++