[Qt-interest] removeRows() crash.

phil prentice philp.cheer at talktalk.net
Thu Apr 23 20:51:30 CEST 2009


My code crashes when I delete an item from a class derived from QListView.  I 
realise that I am probably going to have to cut my code down to get any help 
on this..but I thought that I would pass it by you all first just in case you 
know immediately what this is.

I have over-ridden the method 
QItemSelectionModel::SelectionFlags selectionCommand
                ( const QModelIndex & index, const QEvent * event = 0 ) const;
in QListView.

I need this to decide if an index is to be selected or not (the mouse position 
inside the item will determine this).

I use the code:-
bottomArrowModel.removeRows(m_modelItem.row(), 1, QModelIndex());
to remove a row.  bottomArrowModel is the model attached to the view.

Its defiantly the selectionCommand that is causing the crash.  I think what 
might be happening is that the QModelIndex is being removed by removeRows() 
and then the signal is getting through to the selectionCommand.  At that 
point the QModelIndex() is no longer valid.

The end of the stack trace from the debugger shows:-

/* CRASH!!!! */
#0  0x0805bf1a in QEvent::type (this=0x0)
    at /usr/local/Trolltech/Qt-4.2.1/include/QtCore/qcoreevent.h:221
#1  0x0805b993 in BottomFacilityListView::selectionCommand (this=0x85119a0,
    index=@0xbfb8f86c, event=0x0) at bottomFacilityListView.cpp:79
#2  0x00affe8e in QAbstractItemView::setCurrentIndex (this=0x85119a0,
    index=@0xbfb8f86c) at itemviews/qabstractitemview.cpp:767
#3  0x00b00d80 in QAbstractItemView::rowsAboutToBeRemoved (this=0x85119a0,
    parent=@0xbfb8ff2c, start=0, end=0) at 
itemviews/qabstractitemview.cpp:2570
#4  0x00b13feb in QListView::rowsAboutToBeRemoved (this=0x85119a0,
    parent=@0xbfb8ff2c, start=0, end=0) at itemviews/qlistview.cpp:762
#5  0x00b006c7 in QAbstractItemView::qt_metacall (this=0x85119a0,
    _c=QMetaObject::InvokeMetaMethod, _id=48, _a=0xbfb8fe8c)
    at .moc/release-shared/moc_qabstractitemview.cpp:199
#6  0x00bc6f68 in QListView::qt_metacall (this=0x85119a0,
    _c=QMetaObject::InvokeMetaMethod, _id=48, _a=0xbfb8fe8c)
    at .moc/release-shared/moc_qlistview.cpp:98
#7  0x0805e728 in BottomFacilityListView::qt_metacall (this=0x85119a0,
    _c=QMetaObject::InvokeMetaMethod, _id=48, _a=0xbfb8fe8c)
    at moc_bottomFacilityListView.cpp:60
#8  0x0053e327 in QMetaObject::activate (sender=0xbfb923dc,
    from_signal_index=10, to_signal_index=10, argv=Variable "argv" is not 
available.
) at kernel/qobject.cpp:2909
#9  0x0053e95a in QMetaObject::activate (sender=0xbfb923dc, m=0x5c5918,
    local_signal_index=6, argv=0xbfb8fe8c) at kernel/qobject.cpp:2952
#10 0x0055c0d9 in QAbstractItemModel::rowsAboutToBeRemoved (this=0xbfb923dc,
    _t1=@0xbfb8ff2c, _t2=0, _t3=0)
    at .moc/release-shared/moc_qabstractitemmodel.cpp:160
#11 0x00527b3e in QAbstractItemModel::beginRemoveRows (this=0xbfb923dc,
    parent=@0xbfb8ff2c, first=0, last=0) at kernel/qabstractitemmodel.cpp:2008
#12 0x08059b6a in BottomArrowModel::removeRows (this=0xbfb923dc, position=0,
    rows=1) at bottomArrowModel.cpp:118
#13 0x080515c5 in QTdcwb::deleteFacility (this=0xbfb92328) at QTdcwb.cpp:473
#14 0x0805debe in QTdcwb::qt_metacall (this=0xbfb92328,
    _c=QMetaObject::InvokeMetaMethod, _id=19, _a=0xbfb9049c)
    at moc_QTdcwb.cpp:111
#15 0x0053e327 in QMetaObject::activate (sender=0x851d388,
    from_signal_index=5, to_signal_index=6, argv=Variable "argv" is not 
available.
) at kernel/qobject.cpp:2909
#16 0x0053e75f in QMetaObject::activate (sender=0x851d388, m=0xd16440,
    from_local_signal_index=1, to_local_signal_index=2, argv=0xbfb9049c)
    at kernel/qobject.cpp:2961
#17 0x00788ae4 in QAction::triggered (this=0x851d388, _t1=false)
    at .moc/release-shared/moc_qaction.cpp:203
#18 0x0078973f in QAction::activate (this=0x851d388, event=QAction::Trigger)
    at kernel/qaction.cpp:1068
#19 0x00a6592b in QMenuPrivate::activateAction (this=0x850f440,
    action=0x851d388, action_e=QAction::Trigger) at widgets/qmenu.cpp:749
#20 0x00a66783 in QMenu::mouseReleaseEvent (this=0xbfb923b4, e=0xbfb90b24)
    at widgets/qmenu.cpp:1826
#21 0x007d0ce1 in QWidget::event (this=0xbfb923b4, event=0xbfb90b24)
    at kernel/qwidget.cpp:5574
#22 0x00a62642 in QMenu::event (this=0xbfb923b4, e=0xbfb90b24)
    at widgets/qmenu.cpp:1894

Any ideas???

Meanwhile I will start cutting my code down.

Thanks everyone

Phil



More information about the Qt-interest-old mailing list