[Qt-interest] removeRows() crash.
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Thu Apr 23 23:51:04 CEST 2009
Well.. If you look at the function declaration in the docs, the events'
default value is null :)
QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand
( const QModelIndex & index, const QEvent * event = 0 ) const [virtual
protected]
Returns the SelectionFlags to be used when updating a selection with to
include the index specified. The event is a user input event, such as a
mouse or keyboard event.
Reimplement this function to define your own selection behavior.
See also setSelection().
Since it can be called from setSelection programmatically, there would
be no event associated with it..
Many QT "change handlers" (text changed, selection change, etc etc) can
have different signals emitted if it was changed programmatically or by
the user directly.
So maybe, the selectionCommand allows you to programmatically select an
"invalid" selection state, maybe an initial "un selected state" but that
state is never allowed via the user...
Typing this, I could think of one example... Say you had a list or tree
view, that when selected selects which widget in a stacked widget is
shown.
Programmatically, you set all indexes to an initial unselected state.
However, once the user has selected a row/item, the widget is shown, and
at least 1 widget ALWAYS has to be shown from that point. So selecting
the same index, does NOT unselect the item...
Just a thought.
Scott
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of phil prentice
> Sent: Thursday, April 23, 2009 3:48 PM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] removeRows() crash.
>
> Hi Stephen
>
> Thanks for that...no I did'nt notice that. In fact just for
interest I
> added the check in my selectionCommand() method and I dont appear to
get
> anymore crashes!! The code now looks like:-
>
> QItemSelectionModel::SelectionFlags
BottomFacilityListView::selectionCommand
> ( const QModelIndex & index, const QEvent *event)
const
> {
> /*
> If item is present under mouse & we have a mouse button press then
check
> if mouse is positioned inside facility arrow. Also check if
ctrl+Alt is
> pressed for adding selections to the current selection list.
> */
> if ((index.isValid()) && (event != NULL) &&
> (event->type() ==
QEvent::MouseButtonPress))
> {
> const QMouseEvent *mouseEvent = static_cast<const
QMouseEvent*>(event);
> if(mouseEvent->button() == Qt::LeftButton)
> {
> if((mouseEvent->y() > 20) && (mouseEvent->y() < 40))
> /* I know; should be
enums. */
> {
> QItemSelectionModel *selModel = selectionModel();
> if(m_addSelection == false)
> {
> selModel->clear(); /* Clear all selections. */
> }
> return QItemSelectionModel::Toggle;
> /* Add to current selection list. */
> }
> }
> }
> return QItemSelectionModel::NoUpdate;
> }
>
> Thanks for noticing that....just need to understand...
> why is selectionCommand being called with event = NULL??
>
> At least I have a work-around(??) for now. Any ideas on how best I
could
> investigate further? I guess a cut down in code might be called for.
>
> Your help much appreciated; Thanks again
> Phil
>
>
> On Thursday 23 April 2009 18:44, Stephen Jackson wrote:
> > On 23/04/09, phil prentice wrote:
> > > 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
> >
> > First things first. In BottomFacilityListView::selectionCommand you
> > are calling event->type() but event is a null pointer. Does this get
> > you anywhere?
> >
> > Regards,
> >
> > Stephen Jackson
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> _______________________________________________
> 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