Search code examples
c++cgtkgtkmm

Auto-connection signals with GtkBuilder but on GTKmm


In C, I can autoconnect signals with this code:

gtk_builder_connect_signals (builder, NULL)

How to do this in C++ with GTKmm?


Solution

  • You cannot use Glade to connect your signals when using gtkmm, you need to do that manually.

        Glib::RefPtr builder = Gtk::Builder::create_from_file("glade_file.ui");
    
        Gtk::Window *window1 = 0;
        builder->get_widget("window1", window1);
    
        Gtk::Button *button1 = 0;
        builder->get_widget("button1", button1);
        // get other widgets
        ...
    
        button1->signal_clicked().connect(sigc::mem_fun(*this, &button1_clicked));
    

    Have a look at these answers :

    https://stackoverflow.com/a/3191472/1673000

    https://stackoverflow.com/a/1637058/1673000