[gtkmm] RadioButtons with SignalHandler



I want to register the changing of a RadioButton at a group of RadioButtons
directly. Therefor i grouped some radiobuttons and allocated the group to
radioaction. I tried to connect the signal "signal_changed" from
"RadioAction" with a function via "connect".
But that does not work. It compiles although without errors, but if i start
the program it crashes with a segmentation fault. I wrote an example for the
problem. Maybe someone can help me.

SOME LINKS:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1RadioButton.html
http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1RadioButtonGroup.html
http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1RadioAction.html
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1SignalProxy1.html
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-writing-signal-handlers.html

CODE:

/*************************
 GTKmm - RadioButton TEST

 masi
 26. January 2009

 main.cc
 *************************/

#include <iostream>
#include <gtkmm-2.4/gtkmm.h>

/*** Class Window Main ***/
class class_window_main : public Gtk::Window{

 public:
  class_window_main();
  virtual ~class_window_main(){}; // Inline-Destructor

 protected:

  // Widgets
  Gtk::RadioButton radiobutton1, radiobutton2, radiobutton3;
  Gtk::VBox vbox1;

  // RadioButton Group
  Gtk::RadioButton::Group group_radiobuttons;

  // RadioAction
  Glib::RefPtr<Gtk::RadioAction> ref_radioaction;

  // SignalHandler
  virtual void on_radioaction(const Glib::RefPtr<Gtk::RadioAction>&);
};

/*** Constructor Window Main ***/
class_window_main::class_window_main() :
  vbox1(false, 5),
  radiobutton1("Case 1"),
  radiobutton2("Case 2"),
  radiobutton3("Case 3"){

  // Window
  set_title("Radiobutton - TEST");
  set_default_size(150, 200);
  set_border_width(5);

  // Widgets
  vbox1.add(radiobutton1);
  vbox1.add(radiobutton2);
  vbox1.add(radiobutton3);
  add(vbox1);

  // Grouping RadioButtons
  group_radiobuttons = radiobutton1.get_group();
  radiobutton2.set_group(group_radiobuttons);
  radiobutton3.set_group(group_radiobuttons);
  radiobutton1.set_active();
 
  // Set RadioAction
  ref_radioaction = Gtk::RadioAction::create();
  ref_radioaction->set_group(group_radiobuttons);

  // Connecting SignalHandler
  ref_radioaction->signal_changed().connect(sigc::mem_fun(*this,
&class_window_main::on_radioaction));

  // Run
  show_all_children();
  return;
}

// SingalHandler
void class_window_main::on_radioaction(const Glib::RefPtr<Gtk::RadioAction>
&test_radioaction){

  if(radiobutton1.property_active() == true)
    std::cout << std::endl << "Case 1";
  if(radiobutton2.property_active() == true)
    std::cout << std::endl << "Case 2";
  if(radiobutton3.property_active() == true)
    std::cout << std::endl << "Case 3";

  return;
}

/*** Main Function ***/
int main(int argc, char *argv[]){

  Gtk::Main kit(argc, argv);
  class_window_main window_main;
  Gtk::Main::run(window_main);

  return 0;
} 

CODE END

Thanks!
-- 
View this message in context: http://www.nabble.com/-gtkmm--RadioButtons-with-SignalHandler-tp21674077p21674077.html
Sent from the Gtkmm mailing list archive at Nabble.com.



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