qt-interest@trolltech.com
[Top] [All Lists]

Re: Why does this code work ? :)

Subject: Re: Why does this code work ? :)
From: André Somers
Date: Fri, 18 Feb 2005 15:24:12 +0100
On Friday 18 February 2005 13:48, Jeroen Wijnhout wrote:
> On Friday 18 February 2005 13:37, Devrim Erdem wrote:
> > So it is possible that the item can delete in the doSomething method.
> > And then call the nextSibling method on the point which points to a
> > deleted data. However my application works almost all the time in
> > spite of this incorrect logic.
> >
> > Can anybody tell me why this works ?
>
> Pure luck? (...) So you should never rely on this behavior.
I agree. A save way to do this would be:

QListViewItem* item = group->firstChild() ;
QListViewItem* nextitem;
while( item )
{
    nextitem = item->nextSibling() ;
    item->doSomething() ;
    item = nextitem;
}

André
-- 
My opinions may have changed, but not the fact that I am right.
-- Ashleigh Brilliant
<Prev in Thread] Current Thread [Next in Thread>