[Kde-games-devel] test QPtrList existence ?
cantabile
cantabile.03 at wanadoo.fr
Sat Sep 20 19:47:55 CEST 2003
Hi,
I encounter a simple problem with QPtrList, but can't see why:
when my game is ending, I call a clear() function, which erase the
values in a QPtrList<QCanvasItems>.
When the list has not been used (e.g I call a new game at the start,
without erasing any value in the list), no problem, but when it's been
used, I get a crash pointing to my clear() methtod.
Here's the method :
void KMatchesView::clear()
{
if (!matchesList.isEmpty())
for (uint i=0; i< matchesList.count() ; i++) {
QCanvasItem* match = matchesList.at(i);
if (match->rtti() == matchRTTI) {
delete match;
}
}
//this is the list where are stored pointers to canvas items
matchesList.clear();
}
Here's the method where I erase item in game :
void KMatchesView::play()
{
// iterator of the list of selected sprites
QValueList<int>::Iterator it;
for (it = selectedList.begin(); it !=selectedList.end();it++)
delete matchesList.at(*it);
}
selectedList.clear();
}
Is there something wrong in these methods ?
Is there a way to test if a QPtrList exists (like if (matchesList) ...)
?
Thanks.
More information about the kde-games-devel
mailing list