PDA

View Full Version : Replacement for QTimer?



SKolaMunn
13th October 2011, 20:43
I have a video player that I made using a custom class for dealing with extracting frames from the video (in other words, I'm not using Phonon) and I'm drawing the frames on a QLabel during video playback which I control using QTimer with setInterval. I see that QTimer's setInterval is not sufficient for accurate video playback speed (I set it to 33 ms but the slot is being called ever 46 ms). Is there a recommended method I should use to get accurate playback speed? If my code can't keep up, its okay to skip a frame or something but I need the total time to play the video to be equal to the total time of the video and I assume that messing around with guesses for setInterval until I get it right is not the way to go, especially when this program will be running on different machines and different processes may be occuring during playback (for instance, drawing additional items on the frame). How can I get accurate playback speed?

I greatly appreciate suggestions!

wysota
13th October 2011, 21:51
What Qt version are you using? What Windows version are you on? As far as I know recent Qt versions shouldn't have problems with small intervals on Windows.

ChrisW67
14th October 2011, 05:10
QTimer depends on the program returning to the event loop for signal dispatch so if the program takes 40ms to return to the loop then the timer will be delayed. Are you sure the program returns to the event loop often enough that the timer is not being delayed?

hoffen
14th October 2011, 05:18
Maybe u have the same problem with me , this may help http://www.qtcentre.org/wiki/index.php?title=Keeping_the_GUI_Responsive

SKolaMunn
17th October 2011, 16:55
I didn't notice these responses earlier (I thought I was set up for notifications), anyway, I decided to dynamically adjust the interval based on how long it was taking between calls to the slot and that's been working pretty well. I'm definitely doing some heavy processing in my slot that can bog down the program and sometimes (when drawing a dynamic heat map, for instance) it just can't keep up, but most of the time, it just has to decrease the interval a little bit.

I'm looking at this article that hoffen suggested now, it looks interesting, thanks. Maybe I can improve my timing in a way that's less of a hack!