Web lists-archives.com

Re: gtk_main_quit() as button callback?




To be more precise (I was on my phone earlier)…

On 22 July 2015 at 23:09, richard boaz <ivor.boaz@xxxxxxxxx> wrote:

> g_signal_connect(topWindow, "destroy", G_CALLBACK(gtk_main_quit), NULL);

There's no need to do this: GtkApplication will stop the main loop if
the application's window is the last managed by the application.

> button = gtk_button_new_with_label("QUIT");
> g_signal_connect(button, "clicked", G_CALLBACK(gtk_main_quit), NULL);

You also don't want to do this. If you want the button to close the
window, use gtk_widget_destroy() and g_signal_connect_swapped() on the
"clicked" signal, so that the window will be destroyed, and if it's
the last window managed by the application, the application will quit.

> gtk_main();

Don't nest a main loop in the activate signal handler; GApplication
does all the main loop spinning for you.

> int main(int argc, char **argv)
> {
> int status = 0;
> GtkApplication *app;
>   app = gtk_application_new("quit.example", G_APPLICATION_FLAGS_NONE);
> g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
> status = g_application_run(G_APPLICATION(app), argc, argv);
> g_object_unref(app);

There's no real need to do this — the OS will collect the memory of
your process at the end of it. It only helps if you're running under
Valgrind, or similar tools.

Ciao,
 Emmanuele.

-- 
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list