[Qt-interest] Howto: multiple emissions of signal cause one single slot execution.
Davor J.
DavorJ at live.com
Fri Jun 11 18:13:30 CEST 2010
William Crocker ask for an example. It's similar to his, but here it is:
class HandWaver {
Q_OBJECT
public:
HandWaver() : handRaised(false) {}
public slots:
void raiseHand(){
if (handRaised) return;
/*... code to raise hand ... */
handRaised = true;
//If one wants the hand to be lovered on idle loop, one can
uncomment this:
//QTimer::singleShot(0, this, SLOT(loverHand()));
}
void loverHand(){
if (!handRaised) return;
/*... code to lover hand... */
handRaised = false;
}
private:
bool handRaised;
};
"raiseHand()" is then connected to the raise() signal.
After writing this I am surprised how simple the solution is I was looking
for... In my own case "raiseHand" = "dirtyFlag", and it's checked before
starting the execution of a processintensive task.
Regards,
Davor
<william.crocker at analog.com> wrote in message
news:4C122A16.6010704 at analog.com...
>
>>>
>>> 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.)
>>>
>
> void
> MyApp::raiseHand() {
> if( ! m_RaisHandScheduled ) {
> QTimer::singleShot(0, this, SLOT(doRealRaiseHand()));
> m_RaiseHandScheduled = true;
> }
> }
>
> void
> MyApp::doRealRaiseHand() {
> ... really raise my hand ...
> m_RaiseHandScheduled = false;
> }
More information about the Qt-interest-old
mailing list