How to add a response to a button with Gtkmm

495 views Asked by At

I am trying to add a response to a button in a Gtk::Dialog but I don't know why it does not work I try to type this :

button_quit(Gtk::Stock::QUIT, Gtk::RESPONSE_CLOSE)

but it does not work. Also, I tried to do with an other way like this :

button_quit.signal_clicked().connect([]() {Gtk::Main::quit();});  

but when I clicked on the button I have this error :

(code:7199): Gtk-CRITICAL **: gtk_main_quit: assertion 'main_loops != NULL' failed

So if you know how to solve this it will be very helpful for me.

Thank you.

1

There are 1 answers

0
pan-mroku On

Use add_button.

Gtk::Dialog dialog;
auto button = dialog.add_button("Ok", Gtk::RESPONSE_CLOSE);
dialog.signal_response().connect([&](int response_id)
{
    std::cout<<response_id<<std::endl;
});