PDA

View Full Version : QTimer unnestable with every time i stop/start it



aguayro
20th October 2012, 14:11
Hi

I'm trying to make an image slideshow, it's seems simple, when i move to a QListWidget item its start the slideshow, until another item is selected, then stop the timer and start again the same process.
The problem is every time i select another item, the timer goes "faster". The first selection is fine, timer goes like (1, 2, 3, 4,) (being each number a timer timeout, 1 per second), but the second slection is something like: (1 2, 3 4, 1 2, 3 4) (2 per second), third selection...(1 2 3, 4 1 2, 3 4 1, 2 3 4)...... and more and more....

the app has a lot of code, so this is how basically im doing it:

1: On app load, y create the timer.
2: If the user select an item from the list and slideshow is enbaled, the timer starts, and the slideshow is shown.
3: If the user select another item, first: if(theTimer->isActive()) { theTimer->stop(); }(i do this because if the user set the SLideshow off, so the timer stops untile Slideshow is enabled again) and then, reload the image list, reset the current image counter, and start the timer again.

I don't know the why the timeous are stacking or queueing or somethig like that...
Must i destroy the QTimer and create it every time? If the answer is yes, what is the utilty of QTimmer::stop()??

mvuori
20th October 2012, 15:03
The timers may seem to stack if for some reason there are delays in loading some images. If that is the case, you could stop the timer when entering an image and restart it when it has been loaded -- or by other ways seeing that some transitions between images do not get too short.

(A very first thing to do is to install accurate time measurement with QTime::elapsed())

aguayro
20th October 2012, 17:55
ok, was my fault, a dumb connect signal in wrong place.
Thanks for the help mvuori, thank to you i've dsicarded the timer :)