RE: [gtkmm] Two beginners questions to signal handling



Hello,

> > >is there a way to connect the signal handler
> > >    B::something_in_B_selected() to A::update_values_in_A()?
> > >   class A : public Gtk::VBox
> > >   class B : public Gtk::VBox

> > Here's an example (someone can step in and tell me if this is the
> > preferred way of doing things):
> >    B::something_in_B_selected() to A::update_values_in_A()?
> >    class A : public Gtk::VBox
> >    class B : public Gtk::VBox
> > // Example given here
> > The key is to pass a MainWindow pointer to the MainMenu constructor.
> > You can then use this pointer to MainWindow to connect your signals
> > to any signal handler in MainWindow.  I've declared MainMenu to be
> > a friend of MainWindow in order to allow access to the protected
> > signal handlers.

> > If anyone has a better way of doing this, please speak up. =)
 
> I CAN'T MAKE THE LETTERS ANY BIGGER; but ...

> If the goal is just to get your program working, this is as good
> a way as any - but it defeats the whole purpose of classes.

> One way would be -
> Provide class A with a register() interface function so
> that if an event in B occurs, it is left to A to decide upon
> the necessary action - maybe postpone it! The main thing is
> to act through interfaces so that instances don't become classes!
> e.g.
> class A
> {
> typedef enum { E1, E2, E3 } ACTION;
>   class_B		b;
  
>  void register( ACTION now ) { if( can_do_it( now ) ) do_it(); }
> }

Can you elaborate (or point me to some online resources) on how this register()
interface function works.  In the example above, is the register() function in
class A acting as a signal handler for a signal emitted in class B, thus
resulting in a connection as follows?

b.some_signal().connect( SigC::slot(*this, &A::register) );

If this is the case, what about when class A and class B are two separate
classes (ie. class_A does not encapsulate class_B).  Can you still use the
register method above, or at that point, is the most logical approach to use
multiple inheritance to make class_C which inherits from both class_A and
class_B?  I always thought that passing pointers (as in the original example)
was not the best way of doing things.

> Hope this is useful.

Yes, it is very useful. Thank You for your help!  Sorry for all the questions. 
I'm fairly new to gtkmm and GUI programming in C++ in general.

-- 
Gene Ruebsamen


-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]