Consider the following situation:
class Foo : public QObject {
Q_OBJECT
public:
void set_A(int a) { emit updated(this); }
void set_B(int b) { emit updated(this); }
signals:
void updated(Foo*);
}
Foo f;
connect(&f, SIGNAL(updated(Foo*)), something, SLOT(do_something_heavy(Foo*)), Qt::QueuedConnection)
void bar() {
f.set_A(5); f.set_B(6);
}
How can I ensure that only one of the signals reach the do_something_heavy()
call?
I want to be able to use set_A()
and invoke the do_something_heavy()
, but in the case when both set_A and set_B are invoked, I don't want to do_something_heavy()
twice.
Can I unqueue all remaining outstanding signals for that particular sender/receiver pair? Preferably at emit
, rather than at receive, but that's just for the sake of brevity and encapsulation - I want the updated(Foo*)
to signify the need to change the local receiver's state, and if the connection is queued, the semantics are such that I don't need the update to occur twice.