Re: casting Gtk::UIManager::get_widget()



Sergio,

The reason you're getting errors is because the widget being returned
isn't a CheckButton, its a CheckMenuItem or CheckMenuElem or
something. When doing things like this, I work with the actions
though. Something like this:

Glib::RefPtr< Gtk::Action > act = _ui_manager->get_action( actionName ) ;
Glib::RefPtr< Gtk::ToggleAction > tact =
               Glib::RefPtr< Gtk::ToggleAction >::cast_dynamic( act ) ;

if( tact->get_active() )
{
   //do something
}

HTH,
Paul Davis

On 4/28/07, Sergio Perticone <g4ll0ws gmail com> wrote:
Hi,
I've a menu with a checkbutton, how can I check if is it active?

I've tried this way:

void Window::f()
{
        Gtk::CheckButton* pCheck =
static_cast<Gtk::CheckButton*>(refUIManager->get_widget("/Where/Is/CheckButton"));

        if(pCheck && pCheck->get_active()) {
               // ...
        }
}

But at runtime I get this message:
Gtk-CRITICAL **: gtk_toggle_button_get_active: assertion
`GTK_IS_TOGGLE_BUTTON (toggle_button)' failed

I've also tried dynamic_cast<>() but `pCheck' becomes NULL.

Thanks,

s.
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




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