rendered paste body#include <iostream>
#include <gtkmm.h>
void standalone_function ()
{
std::cout << "standalone_function" << std::endl;
}
class MyButton : public Gtk::Button
{
public:
MyButton (const Glib::ustring& lbl) :
Gtk::Button (lbl) {}
void on_clicked () { std::cout << "on_clicked" << std::endl; }
};
class AnotherButton : public Gtk::Button
{
public:
AnotherButton (const Glib::ustring& lbl) :
Gtk::Button (lbl)
{
signal_clicked ().connect (sigc::mem_fun (*this,
&AnotherButton::my_handler));
}
void my_handler ()
{
std::cout << "my_handler" << std::endl;
}
};
int main(int argc, char** argv)
{
Gtk::Main kit (argc, argv);
// if you don't use inheritance, connect to the signal
Gtk::Button button1 ("ptr_fun");
button1.signal_clicked ().connect (sigc::ptr_fun (&standalone_function));
// this class defines the virtual function on_clicked, which will automatically
// run when the signal is emitted, you don't need to explicitly connect it.
MyButton button2 ("on_clicked");
AnotherButton button3 ("mem_fun");
Gtk::Window win;
Gtk::VBox vbox;
win.add (vbox);
vbox.pack_start (button1);
vbox.pack_start (button2);
vbox.pack_start (button3);
win.show_all ();
Gtk::Main::run (win);
}