ahaan...

I removed the item i did not want and delete the pointer which was pointing to it by the following code. And my program then worked fine.
Qt Code:
  1. //sqMap is the class used for creation of squares
  2. sqMap square = new sqMap(width, height)
  3. ...
  4. ...
  5. scene->removeItem(square);
  6. delete square;
To copy to clipboard, switch view to plain text mode 

But now i need to delete multiple last drawn items. So what i did was that i made a vector of type *sqMap and then pushed the items i wanted to delete into it and then removed and deleted them one by one. But some/all of the items don't get removed from the screen. Following code was used

Qt Code:
  1. ...
  2. ...
  3. ...
  4. std::vector<sqMap *> sqrBasket;
  5. ...
  6. ...
  7. ...
  8.  
  9. for(int pos=0 ; pos<sqrBasket.size(); pos++)
  10. {
  11. scene->removeItem(sqrBasket[pos]);
  12. delete sqrBasket[pos];
  13. }
  14. for(int j=0; j<=i; j++)
  15. {
  16. tempHeight = array[j] / tempWidth;
  17. [B]square = new sqMap(tempWidth, tempHeight);[/B]
  18. square->setPos(xLocation,yLocation);
  19. int size4toolTip = int(array[j]) * sum / (width * height);
  20. QString toolTip = QString::number(size4toolTip,10);
  21. square->setToolTip(toolTip);
  22. [B] sqrBasket.push_back(square);[/B]
  23. scene->addItem(square);
  24. ...
  25. ...
  26. ...
To copy to clipboard, switch view to plain text mode 

Does the proedure of removing mulitple items that i have followed is right?