[Qt-interest] Howto: multiple emissions of signal cause one single slot execution.
Davor J.
DavorJ at live.com
Fri Jun 11 14:04:16 CEST 2010
Suppose you have a signal "raise()" and a slot "raiseHand()". Suppose that
several objects can emit the "raise()" signal, simultaneously, during their
function executions, etc... Suppose now that during execution the "raise()"
signal is emitted several times in a continuous execution while the event
loop is non-idle. Suppose all this happens in one main thread.
Now the question: How would you execute "raiseHand()" only once in such a
scenario? (In other words: You don't want to raise the hand on every single
yell, but as a confirmation on all the yells, given a certain happening.)
I was thinking on something as QTimer::singleshot(0, this,
SLOT(raiseHand())), as it executes "raiseHand()" when the event loop becomes
idle. But still, it would execute as many times as "raise()" is called.
An other option is to use a timer that resets itself after some 5-10msec,
and only triggers the "raiseHand()" if it is allowed to timeout. But this
seems a workaround and isn't pretty. Best would be to execute it only once
when the event loop is idle.
Has Qt framework support for this? Or has anyone better suggestions?
Regards,
Davor
More information about the Qt-interest-old
mailing list