PDA

View Full Version : deletion problem with QGraphicsScene



spawn9997
26th February 2010, 20:44
Using Qt 4.4.2 (for now)
I have been working with a partner on a project that displays 10's to 100's of thousands of QGraphicsItem's in a QGraphicsScene. The problem is it takes 5-10 times longer to delete the items than it did to create them.
The goal is to close one project and load another one in the same scene or close the program without hanging up the application.
What we have been trying to do is call delete on the scene and then open a new project (This may involve creating another few thousand QGraphicsItem's).
Solutions tried have been ... 1) to try and wait for the scene to completely delete everything; 2) to move the scene to a Thread and delete it there; 3) Untried!!! to clear the scene but NOT delete it at all.

My questions are... A) Is it safe to move a QGraphicsScene to another thread if solely for the purpose of deleting it w/o delaying the GUI thread? B) Is it any faster to clear a scene without deleting it? C) What other ways could be used to accomplish my goal?

Any and all help appreciated,

JW
SW Developer

p.s.: Not sure if this is newbie question or not; I just don't see any info on this anywhere.

Lykurg
26th February 2010, 21:24
Hi, first I haven't dealed with such a huge amount of items. Some thought coming to my mind (without testing if they improve speed):
a) can you reuse your once created items?
b) use removeItem() to remove them fast from the scene and then delete only the items in a worker thread.
c) while changing the scene use QObject::blockSignals() to fasten your operations up. (also turn the index off)

Lykurg

spawn9997
26th February 2010, 21:49
Lykurg --
Hey, those are some good ideas. I had thought of reusing items but have forgotten about simply removing items from the scene. I'll try this and see what happens.

jw