1

In my Qt GUI, I have QGraphicsScene where QGraphicsItems are added. Now in order to delete the items, I'm using GraphicsScene::selectedItems() to return a list of items selected on the screen. This returns the memory address of selected items, their position and flag as a comma separated array.

Now how do I use this result "QList<QGraphicsItem*> as an argument to QGraphicsScene::removeItem()?

UPDATE **** Item added to the scene is from a class derived from GraphicsItem. And each class creates a text file when the item saddled to the scene. So when this item is deleted the text file also should be deleted. If I'm gonna use the above method, I cant do that. Rather I prefer to get the object being selected by QGraphicsScene::selectedItems and then use the member function from the class to delete the file associated with it. How do I do this. Please explain thank you so much

Vino
  • 167
  • 2
  • 14
  • possible duplicate of [Deleting a QGraphicsItem/QGraphicsObject from QGraphicsScene?](http://stackoverflow.com/questions/31905718/deleting-a-qgraphicsitem-qgraphicsobject-from-qgraphicsscene) – TheDarkKnight Aug 12 '15 at 12:32

1 Answers1

1
foreach (QGraphicsItem * i, selectedItems()) removeItem(i);
dtech
  • 47,916
  • 17
  • 112
  • 190
  • Bro, each item added to the scene is from a class derived from GraphicsItem. And each class creates a text file when the item saddled to the scene. So when this item is deleted the text file also should be deleted. If I'm gonna use the above method, I cant do that. Rather I prefer to get the object being selected by QGraphicsScene::selectedItems and then use the member function from the class to delete the file associated with it. How do I do this. Please explain thank you so much :) – Vino Aug 12 '15 at 03:34
  • Remove the file in the item destructor... and after `removeItem(i)` also call `delete i`. `removeItem(i)` doesn't delete the item, only removes it from that particular screne. – dtech Aug 12 '15 at 03:36