This is about destroying QGraphicsItem instances. I partly refer to this thread here:
http://lists.trolltech.com/qt4-previ...ad00056-0.html

What I've tried is to implement a one shoot delete for QGraphicsItem as in the thread above. I'll give my code here:

Qt Code:
  1. // this is in the actual object that is deleted by pressing the del key.
  2. // edge is a subclass of QGraphicsItem. first the edge is retrieved (once
  3. // as an edge and once as item), then the lists are updated and finally
  4. // the edges and the current node are remembered for deleting.
  5.  
  6. void
  7. DrawNode::keyPressEvent(QKeyEvent* e)
  8. {
  9. if (e->key() == Qt::Key_Delete) {
  10. for (int i = 0; i < edgeList.count(); i++)
  11. {
  12. Edge *edge = edgeList[i];
  13. QGraphicsItem *item = edgeList[i];
  14.  
  15. if (edge && edge->sourceNode() != this)
  16. {
  17. if (edge->sourceNode()->edges().contains(edge))
  18. edge->sourceNode()->edges().removeAll(edge);
  19. }
  20. else if (edge && edge->destNode() != this)
  21. {
  22. if (edge->destNode()->edges().contains(edge))
  23. int removed = edge->destNode()->edges().removeAll(edge);
  24. }
  25. graph->deleteItemLater(item);
  26. }
  27. graph->deleteItemLater(this);
  28. }
  29. }
  30.  
  31. =====================
  32.  
  33. // this is a signal/slot one shoot timer for the deletion of the scheduled
  34. // objects. it is implemented in GraphWidget, which is a subclass of QGraphicsView
  35.  
  36. void
  37. GraphWidget::deleteItemLater(QGraphicsItem* item)
  38. {
  39. m_itemsToDelete.append(item);
  40. QTimer::singleShot(1000, this, SLOT(deleteItems()));
  41. }
  42.  
  43. // private slot
  44. void
  45. GraphWidget::deleteItems()
  46. {
  47. foreach (QGraphicsItem* item, m_itemsToDelete) {
  48. scene()->removeItem(item);
  49. delete item;
  50. item = NULL;
  51. }
  52. m_itemsToDelete.clear();
  53. }
To copy to clipboard, switch view to plain text mode 

when deleting an object everything is fine, but trying to move the adjacent node the program crashes here:

Qt Code:
  1. void Edge::adjust()
  2. {
  3. if (!source || !dest /*|| !(source->getGraph()) || !(dest->getGraph())*/)
  4. return;
  5.  
  6. QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0));
  7. ....
  8. }
To copy to clipboard, switch view to plain text mode 

As you can see this code is executed inside the edge class. The this pointer evaluates to a valid address, but the QGraphicsItem part (Edge is subclassed from QGraphicsItem) has the sound name 0xfeeefeee. the same goes for the two node members which are also subclasses of QGraphicsItem.
Somehow it seems that the edge is not really deleted (i can't say for the node so far), but only it's QGraphicsItem pointer set to a strange value.
Does anybody know how I can delete delete my Edges and Nodes?

thanks!