[Kde-games-devel] test QPtrList existence ?

Martin Heni martin at heni-online.de
Sun Sep 21 22:29:45 CEST 2003


Be generally careful with QT Lists when they are on
autodelete. You often end up deleting your canvas items
twice.  I tend to setAutoDelete(false) and do the stuff manually.
No idea whether this is your problem, but I quite usually
run into this problem.



At 18:47 20.09.2003 +0200, you wrote:
>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.
>
>_______________________________________________
>kde-games-devel mailing list
>kde-games-devel at mail.kde.org
>http://mail.kde.org/mailman/listinfo/kde-games-devel



More information about the kde-games-devel mailing list