0
I am building a dynamic menu using Gtkmm. The menu is built as follows:
Gtk::RadioButtonGroup appRadioGroup;
bool groupInitialized = false;
Gtk::Menu *driverSubMenu = Gtk::manage(new Gtk::Menu);
driverSubMenu->set_visible(true);
Inicio Loop...
Gtk::RadioMenuItem *appMenuItem = Gtk::manage(new Gtk::RadioMenuItem);
appMenuItem->set_visible(true);
appMenuItem->set_label("Nome da opção");
if (!groupInitialized) {
appRadioGroup = appMenuItem->get_group();
appMenuItem->set_active(true);
groupInitialized = true;
} else {
appMenuItem->set_group(appRadioGroup);
}
appMenuItem->signal_toggled().connect([this, &appMenuItem]() {
this->onApplicationSelected(appMenuItem);
});
driverSubMenu->append(*appMenuItem);
Fim Loop...
The method that treats the signal is:
void onApplicationSelected(Gtk::RadioMenuItem *item) {
if(!item) {
return;
}
if(item->get_active()) {
std::cout << "Item is active " << std::endl;
} else {
std::cout << "Item is not active " << std::endl;
}
}
My problem is with this Signal Handler. When I try to invoke any method in the variable item I get critical errors from GTK+.
For example: when invoking the method get_active()
i get the following error:
Gtk-CRITICAL **: gtk_check_menu_item_get_active: assertion 'GTK_IS_CHECK_MENU_ITEM (check_menu_item)' failed
What am I doing incorrectly? How can I correctly check the status of a Radiomenuitem?