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;
}
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;
}