PDA

View Full Version : Performance of scene(QGraphicsScene) with update();



mukunda
11th January 2011, 11:25
I am trying to update graphics scene by calling update() . When i wanted to scroll down the scene after some time, the application performs the action after some time(15 sec or more). I am updating the scene in the particular view port region. Totally the application gets slow like after 1hr or more and does not respond. Is there any solution to this so that application does not get slow for continuous running

Sample Code :

while(true)
{
scene->update(view->mapToScene(view->visibleRegion().boundingRect()).boundingRect().toR ect());
sleep(1);
}

The above code runs in a thread.

JohannesMunk
12th January 2011, 17:16
Hi!

Lacking a more precise task description, i would recommend using a timer in the GUI-main-thread instead of a sleeploop in a separate thread. I'm pretty sure QGraphicsScene is not thread safe and intended to be accessed only from the main-thread. Don't use QTimer::singleshot, but a periodic timer with QTimer::start for better reliability. The delay should be related to your screen update frequency. DVI = 60Hz thus 16ms interval.

HIH

Johannes

wysota
12th January 2011, 21:18
I'm suprised the application doesn't crash since you are accessing QObjects across threads.

Anyway, if you need such an arbitrary update then most likely you have implemented something incorrectly in your scene. A change to the scene should cause it to update automatically and not using a timer of any sort. It's likely you don't call update() on some item when it changes.

mukunda
13th January 2011, 06:02
I'm suprised the application doesn't crash since you are accessing QObjects across threads.

Anyway, if you need such an arbitrary update then most likely you have implemented something incorrectly in your scene. A change to the scene should cause it to update automatically and not using a timer of any sort. It's likely you don't call update() on some item when it changes.

I've the application like data will be coming from a device continously by which the items in the scene should be shown with color like digital values(green or red) and running values on the scene.so i've to update the scene for every 20ms.

wysota
14th January 2011, 12:21
I've the application like data will be coming from a device continously
So when the data comes, process it and as part of processing call update() on any item that is changed by the data.


by which the items in the scene should be shown with color like digital values(green or red) and running values on the scene.so i've to update the scene for every 20ms.
Updating every 20ms yields little sense. You won't be able to notice such frequent updates (50Hz), you'll just be wasting processing cycles. Data processing should also be a result of receiving a notification that there is something to be processed, not upon a timer timeout (unless you have no other choice but then I'd reduce the frequency to around 10Hz max).