gtk-rs / gtk3-rs

Rust bindings for GTK 3
https://gtk-rs.org
MIT License
508 stars 90 forks source link

[HELP] Exiting an application using a button #751

Closed tataDan closed 2 years ago

tataDan commented 2 years ago

I have a cancel button as created as follows: let cancel_button = gtk::Button::with_label("Cancel");

This code does print the text to the console as expected:

cancel_button.connect_clicked(glib::clone!(@weak window => move |_| {
        println!("Cancel button clicked");
 }));

Suppose I wanted to use this button to gracefully exit the application (basically doing what clicking on the close icon in the titlle bar would do).

What would be the best way to do this?

sdroege commented 2 years ago

If you use gio::Application / gtk::Application then call quit() on it. If you just use a mainloop, call quit() on that.