[Qt-interest] Controlling when timers run
Glenn Hughes
ghughes02138 at gmail.com
Thu Jan 14 23:05:28 CET 2010
> You could just set a flag that describes whether you are able to safely process
> your data or not. Then check this flag at the start of the slot called by the
> timer.
>
> Alternatively, when you start to update your data, disable the timer (or block
> it's signals), then when your data is in a consistent state restart the timer
> (or unblock its signals).
These are good suggestions were I starting from scratch, but they are
going to be difficult to retrofit onto a program of this size. A lot
of our code is predicated on the notion that a particular style of
timer task only runs when the stack is completely unwound, i.e. not in
the middle of other processing. But... perhaps what you suggest is the
best that I'll be able to do under Qt.
... but timers can get you into all sorts of problems unless you have
some ability to know what context they're going to be called in.
For example, suppose rather than doing a million little region
invalidations, I batch them up and then issue them using a timer
task... but then suppose that somehow the timer task gets called in
the middle of repainting. This can lead to an endless series of
inval/paint/inval/paint calls.
There are many cases when the whole point of launching the timer task
is to do something "after everything else in the current action is
done"... but, if in the middle of all that a dialog pops up, or a
system call is made that allows timers to run, the semantic is broken.
Thanks
G
More information about the Qt-interest-old
mailing list