c++ - Qt - invoke slot only when both signals are emitted -
i have 3 processes: a
, b
, final
. final
depends on both a
, b
, can/must updated when both a
, b
updated. there signal datachanged
updates both a
, b
(and final
well). slots update_a
, update_b
invoked other signals.
mainwindow::mainwindow(qwidget* parent) : qmainwindow(parent), pa(false), pb(false) { ... connect(this, &mainwindow::xchanged, this, &mainwindow::update_a); connect(this, &mainwindow::ychanged, this, &mainwindow::update_b); connect(myobj, &myclass::datachanged, this, &mainwindow::update_a); connect(myobj, &myclass::datachanged, this, &mainwindow::update_b); connect(this, &mainwindow::a_updated, this, &mainwindow::update_final); connect(this, &mainwindow::b_updated, this, &mainwindow::update_final); ... } void mainwindow::update_a() { if (!this.pa) { // } this.pa = true; emit a_updated; } void mainwindow::update_b() { if (!this.pb) { // } this.pb = true; emit b_updated; } void mainwindow::update_final() { if (this.pa && this.pb) { // this.pa = false; this.pb = false; } }
is there anyway combine signals , operator rid off using pa
, pb
? or did use signals , slots in wrong way?
edit: sorry forgot mention: update_a
, update_b
invoked other signals, have keep them separated slots. , updated question , code above.
no, there's no supplied signal combination operators in qt. you'll need implement own, have done, or like:
void mainwindow::update_a() { if (!pa) { // } pa = true; if (pa && pb) emit ab_updated(); }
if use pattern frequently, may worthwhile define object class sole responsibility of logical operations on signal sequences. complete, want 'a before b' , 'a after b' operators too.
Comments
Post a Comment