c++ - What is the recommended way of working with QActions in multiple level hierarchy of widgets? -


i'm planning on using qactions use globally in application. idea have action available @ level in widget parent/child hierarchy.

let's have following gui:

+--------------+ | +----------+ | | |  +----+  | | | |  | w2 |  | | | |  +----+  | | | |    w1    | | | +----------+ | |  mainwindow  | +--------------+ 

w2 has qpushbutton want use qaction defined in mainwindow. question is: recommended way of working qactions in multiple level hierarchy of widgets?

here approaches:

  1. define actions in mainwindow singleton, , access w2 add qaction qpushbutton.

  2. define actions in mainwindow , add them w1, in turn add qaction w2, in turn add action qpushbutton (i don't one).

  3. create delegate singleton class hold qactions , access mainwindow make global connections of qactions' triggers backend (model), , access w2 add action wanted qpushbutton.

thanks

personnally, i'd go modified version of second option, in other way, because keeps hierarchy of program. other way because make w2 pushbutton propagate signal mainwindow. advantage option if add w2 in w1, have connect w1, mainwindow stay same (encapsulation). same thing, if add w1 in mainwindow, have connect new w1 mainwindow , don't have care pushbutton in w2 of new w1.

here code make solution works:

in w2 class constructor:

connect(pushbutton, signal(clicked(bool)), this, signal(buttonclicked(bool))); 

in w1 class constructor:

connect(widget2, signal(buttonclicked(bool)), this, signal(buttonclicked(bool))); 

in mainwindow class constructor:

connect(widget1, signal(buttonclicked(bool)), anyaction, signal(triggered(bool))); connect(anyaction, signal(triggered(bool)), this, slot(onactiontriggered(bool))); 

obvisouly, must define correct signals/slot in class definitions , sure whatever connect has been created.

hope helps.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -