Re: [gtkmm] Converting from GTK+ to Gtkmm



Roger Leigh <roger whinlatter uklinux net> writes:

> Murray Cumming Comneon com writes:
> 
> > 1. With libglademm, you need to manually connect your signals after getting
> > the widgets from the Gnome::Glade::Xml. There is no autoconnect yet.
> 
> OK.  Is this planned for the future?

I think it is in that sense that every time someone asks about it,
Murray replies that it is worthwhile, and that someone ought to look
at it (and then usually suggest that the person asking for it looks
into it).

But actually I don't see how - if you restructure your application to
have a proper OO structure as hinted in "Programming with gtkmm", you
most often need to connect signals to specific objects. It would need
quite some amount of ingenuity to make auto-connection work with that.
Truth is it's only a minor hassle once you get used to it.

> This is my class (which I think is the correct way to do things in
> Gtkmm):

Yeah, it's at least one way. Some (mostly minor) comments:

> class ogcalc : public Gtk::Window
> {
> public:
>   ogcalc();
>   virtual ~ogcalc();
> 
> protected:
>   // Signal handlers
>   virtual void calculate(); // Calculation callback
>   virtual void reset();     // Reset callback

I think it's odd that you make these virtual, since I wouldn't have
thought the class would be suitable as a base class (but then I don't
know you design intentions).

> ogcalc::ogcalc()
> {
>   // Get the Glade user interface and add it to this window.
>   xml_interface = Gnome::Glade::Xml::create("ogcalc-gl.glade");
>   xml_interface->reparent_widget("vbox1", *this);

Just a suggestion: I usually rename all widgets (like "outer_vbox")
so that it is easier to read the widget tree. It helps when the
interface gets larger.

>   // Pull all of the widgets out of the Glade interface.
>   xml_interface->get_widget("pg_entry", pg_entry);
> [...]
>   xml_interface->get_widget("calculate_button", calculate_button);
> 
>   // Set up signal handers for buttons.
> [...]
>   if (calculate_button && reset_button)
>     {
>       calculate_button->signal_clicked().connect( SigC::slot(*this,
>                                                              &ogcalc::calculate) );
>       calculate_button->signal_clicked().connect( SigC::slot(*reset_button,
>                                                              &Gtk::Widget::grab_focus) );
>     }

I'm not sure it makes sense to check the return values before
connecting to the signals. Glade will issue a warning, and if they're
0, your application will segfault anyway.

>   // Set up signal handlers for numeric entries.
> [...]
>   if (cf_entry)
>     cf_entry->signal_activate().connect( SigC::hide_return( SigC::slot(*this,
>     &Gtk::Window::activate_default) ) );
> }
>
> This all works, but with one exception.  The last signal hander
> (Gtk::Window::activate_default()) returns a bool, so I can't connect
> it with SigC::slot.  The sigc++ documentation says to use
> SigC::hide_return, but using the above call results in a segfault when
> it is triggered (gdb shows it use up all the stack as it recurses
> forever).

I don't have much clue, but are you sure active_default doesn't active
the entry? Have you tried inserting a middle method that simply calls
activate_default?

-- 
Ole Laursen
http://www.cs.auc.dk/~olau/



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