Performance of scene(QGraphicsScene) with update();
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().to Rect());
sleep(1);
}
The above code runs in a thread.
Re: Performance of scene(QGraphicsScene) with update();
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
Re: Performance of scene(QGraphicsScene) with update();
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.
Re: Performance of scene(QGraphicsScene) with update();
Quote:
Originally Posted by
wysota
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.
Re: Performance of scene(QGraphicsScene) with update();
Quote:
Originally Posted by
mukunda
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.
Quote:
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).