PDA

View Full Version : SetText/SetValue for QLabel/QSlider severely slows down application



erila107
19th October 2011, 21:07
I've a Video application. It consists of some different widgets.

I use on QGraphicsScene with OpenGL to render a video clip. This is done by drawing a square using polygon and then applying a texture, the video frame, on that polygon. Doing that will let the hardware scale everything. But I have a real performance problem.

The QGraphicsScene has a timer that will get the next frame and then call update. It also will emit a signal telling the new frame number. There are one other widget that will listen to this signal and update a QLabel with how many seconds have been played. A QSlider is also updated to visualize how far in the movie we are. Doing these two updates will slow down the application extreme.

When playing a clip with 60 fps and NOT updating the QLabel and QSlider I can see that the timer will generate a signal each 16 mS (exactly what the timer is set on). But when updating the QLabel/QSlider it will take between 30-40 mS between the timer timeout even though it is set to 16 mS.

I think I've made som thread problem, but can not really figure it out.

stampede
20th October 2011, 09:22
Just a guess (its hard to do more without seeing some code), but maybe the QSlider's "valueChanged()" signal is connected to a slot where you grab frame, to let user navigate the video with the slider. So it could happen that each frame is grabbed twice - once when you grab it with timer, then you update the slider - the slider generates "valueChanged" signal, which launches a slot that grabs the same frame again.
I'm just guessing, but the processing time is ~2x longer, so maybe thats the case.
We can help more if you show us some code.

Spitfire
20th October 2011, 11:07
Updating the slider 60 times per second sounds bit extreme (if that's what you're doing).

Test how long it takes to update the QLabel/QSlider on its own without any extra strings attached, in my case it's well below a ms (~0.02 in fact).

Try to add another timer that fires every 1s and updates the label/slider.

erila107
22nd October 2011, 17:12
Just a guess (its hard to do more without seeing some code), but maybe the QSlider's "valueChanged()" signal is connected to a slot where you grab frame, to let user navigate the video with the slider. So it could happen that each frame is grabbed twice - once when you grab it with timer, then you update the slider - the slider generates "valueChanged" signal, which launches a slot that grabs the same frame again.
I'm just guessing, but the processing time is ~2x longer, so maybe thats the case.
We can help more if you show us some code.

I'm sorry for the late replay, I've been in parts of Sweden where there are no connection on my mobile internet :-(

No! I have fixed that one before I find this problem :-)

I've measured how long it take just to update the QSlider and QLabel. If I use a QTimer it says 0 mS. So I'm pretty sure that it is not the time that it takes to change the value that's the problem. I'm more thinking that the has to be some thread scheduling problem or simular.

Just for the fun of it I put in a small loop instead of updating the QLabel/QSlider. This loop is just doing som random calculations on random numbers (no way for the compiler to optimize). I made that loop just to burn CPU power for about 5-10 mS. Even when doing that there is no problem. The problem occurs when I start updating controls in the Qt UI.

The rational by updating the slider 60 times per second is that the slider is pretty wide and I want to have a smooth movement. It would probably be ok to have it update the slider 5-15 times per second, but as I see it that is just to but a bandaid on the problem and not fixing the source of the problem.

Spitfire
24th October 2011, 12:00
You need to show us some code if possible, it'll be much easier this way.