[Qt-interest] removeRows() crash.

phil prentice philp.cheer at talktalk.net
Fri Apr 24 00:24:58 CEST 2009


Hi Ellen 
No I'm not using  a QSortFilterProxyModel.  I also do remember having a 
similar crash situation when I used a Filter on a different application and I 
asked Trolltech about it.  They sent me the followingcomment:-

   The problem you are experiencing is that you are removing indices (by
    swapping models) in a slot that is connected to a signal in the view.
    Since this is a direct connection (instead of queued) the signal
    emission will not return until the code inside the slot has finished
    executing. In your case, when control returns to the code that emitted
    the signal, the index that it was working with has been deleted and the
    view does not know this and hence you can get segmentation faults. The
    solution here is to force the index deletion to happen at a later time.
    This can be done with a QTimer as Jan Erik suggested, or this can be
    done using a queued connection in your "connect" function.

  I had to change my code by adding Qt::QueuedConnection i.e.

  connect(startPushButton,SIGNAL( pressed() ),this,SLOT( startSearch()),
                                                        Qt::QueuedConnection);

  Alas I did not fully understand the reasoning they gave...but it did fix it 
for me.  But in my case I was deleting the sorting model in the slot and 
creating a new one.  I thought that I should mention it just in case it might 
be useful.

  Having said the above...I do wonder if I have some sort of similar problem 
here, even though I am not using a Filter.

Thanks for your interest

Phil
 
On Thursday 23 April 2009 18:39, Ellen Kestrel wrote:
> Are you trying to use a filter implemented with a QSortFilterProxyModel?  I
> had a crash with removeRows that was fixed when I removed the filter and
> reimplemented it in a different class, although I was using a QTreeView and
> not a QListView.  If you find out a better way to fix it, though, I would
> be very interested in hearing it.
>
> - EK
>
> On Thu, Apr 23, 2009 at 11:51 AM, phil prentice 
<philp.cheer at talktalk.net>wrote:
> > 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
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list