[Qt-interest] Crash in QAbstractTableModel.beginRemoveRows
Stephen Kelly
steveire at gmail.com
Fri Dec 10 17:38:54 CET 2010
Niklaus Hersche wrote:
> Hi
>
> I have implemented an Model/View, where the Model runs in it's on thread.
> With a sample interval of 500ms it collects data an writes to a ring
> buffer stored in a file.
> After inserting a new record to the full ring buffer I call:
>
> beginInsertRows ( QModelIndex(), m_Index.lineCount(),
> m_Index.lineCount()); endInsertRows();
> beginRemoveRows ( QModelIndex(), 0, 0);
> endRemoveRows();
>
> This is not very elegant, but I to now a better(:
> Any better solution?
>
> The application, after while, crashes in:
> QtCored4.dll!QHashData::nextNode(QHashData::Node * node=0x00fa8b70)
> QtCored4.dll!QHash<QModelIndex,QPersistentModelIndexData
> *>::const_iterator::operator++()
> QtCored4.dll!QAbstractItemModelPrivate::rowsAboutToBeRemoved(const
> QModelIndex & parent={...}, int first=0, int last=0)
> QtCored4.dll!QAbstractItemModel::beginRemoveRows(const QModelIndex &
> parent={...}, int first=0, int last=0)
>
> The node data is corrupt!
>
> The thread has its own event loop. I use a timer for the sample interval.
> DataLogThread()
> : m_enabled( false)
> , m_SampleIntervalMs( 0)
> , m_SampleTimerId( 0)
> {
> moveToThread( this);
> }
>
>
> What could be the reason for the crash? Is it threading problem?
Yes. The model must live in the same thread as the view.
>
> Thank you
> Nik
More information about the Qt-interest-old
mailing list