4

I am using a QGraphicsScene to display a very large number of items, often more than 100,000. When I call delete the scene, it takes an unusually long time to complete, 10 seconds or more.

A bit of experimenting revealed that the QGraphicsScene::clear function is the slow part. If I clear first and then delete, the clear is slow but the delete is fast.

Why is the QGraphicsScene destructor/clear function so slow, and is there any way I can speed it up?

rrwick
  • 619
  • 7
  • 19

1 Answers1

5

I discovered that the problem relates to the fact that my QGraphicsScene was being displayed in a QGraphicsView. If I first called view->setScene(0) to remove my scene from the view, then the scene would delete much more quickly.

I figured it out by using callgrind to see which functions were being called during QGraphicsScene::clear, and I saw that QGraphicsView functions were taking up the time. I'm not sure, but I suspect QGraphicsView is updating something about itself for each deleted object.

rrwick
  • 619
  • 7
  • 19