[Qt-interest] Selective removal of GraphicsItems on a QGraphicsScene
Andreas Unger
andi.unger05 at gmail.com
Fri Dec 4 06:56:46 CET 2009
Hello all,
I have a number of object that are derived classes of QGraphicsItem on a
QGraphicsScene (mainly QGraphicsProxyWidgets and QGraphicsRectItems). What
I'm trying to do is maintain a small list of QGraphicsItems such that when I
want to clear the scene I iterate through all scene->items() list, check if
each item is in the list of widgets that aren't meant to be deleted and if
its not, I remove it from the scene and delete it. That way, the items that
I do not want to delete remain on the scene. That doesn't work for some
reason. All items are still deleted, and no pointer in my list of items
matches the pointers in the scene->items()
The other scheme that I tried was to first remove the items that I do not
want to delete from the scene, clear the scene via scene->clear(), and then
add those items back to the scene. This works for the most part, but then
again my application crashes randomly. Looking at the stack trace, the
problem appears to be in the QGraphicsScene::addItem method in
qgraphicsscene.cpp. The specific part in the method where the app crashes
is:
} else if (!widget->parentWidget()) {
// Adding a widget that is not part of a tab focus chain.
QGraphicsWidget *last = d->tabFocusFirst->d_func()->focusPrev;
I think this only happens if the item is a QGraphicsProxyWidget. I get an
access violation exception on the last line. Any clue what could be going
on?
Regards,
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091204/3be12be2/attachment.html
More information about the Qt-interest-old
mailing list