If you're calling g_application_run() then you don't need to call
gtk_main() as well: the run() method will spin the main loop for you.

You also don't use gtk_main_quit() to stop the application's main loop: you
should use g_application_quit() instead.

Ciao,
 Emmanuele.

On Wednesday, July 22, 2015, richard boaz <ivor.b...@gmail.com> wrote:

> hi,
>
> I'm in the process of converting my app from v2 to v3 and have come across
> something strange:
>
> Attaching gtk_main_quit() to a button's click callback does not result in
> the application quitting.
>
> What I see:
>
>    1. attaching gtk_main_quit() to the to the top window destroy signal
>    works fine, i.e., quit the app using the WM 'x'
>    2. attaching gtk_main_quit() to a button does not work:
>    2.1) first click - nothing happens
>    2.2) each subsequent click - warning message is written to the cmd
>    line:
>
>        gtk_main_quit: assertion 'main_loops != NULL' failed
>
>    3. gdb tells me that gtk_main_quit() is correctly invoked on the
>    button click
>    4. I will also deduce from the warning message that the main loop is
>    actually gone after the first click
>
> So why does gtk_main() not return?
>
> This worked as expected in GTK2.
>
> The following minimal program (top window + quit button) demonstrates this
> strangeness.  Could this be platform-specific somehow?  (Ubuntu 14.04)
>
> any insights appreciated,
>
> richard
>
> == quit button example ==
> // save to quit.c
> // compilation:
> // gcc quit.c `pkg-config --cflags --libs gtk+-3.0` -g -o quit-button
>
> #include <gtk/gtk.h>
>
> static void activate(GtkApplication *app, gpointer nil)
> {
> GtkWidget    *topWindow, *button;
>  topWindow = gtk_application_window_new(app);
> gtk_container_set_border_width(GTK_CONTAINER(topWindow), 2);
>
> * g_signal_connect(topWindow, "destroy", G_CALLBACK(gtk_main_quit), NULL);*
>  button = gtk_button_new_with_label("QUIT");
> * g_signal_connect(button, "clicked", G_CALLBACK(gtk_main_quit), NULL);*
> gtk_container_add(GTK_CONTAINER(topWindow), button);
>  gtk_widget_show_all(topWindow);
> gtk_window_resize(GTK_WINDOW(topWindow), 300, 350);
> gtk_window_set_position(GTK_WINDOW(topWindow), GTK_WIN_POS_CENTER_ALWAYS);
> gtk_main();
> }
>
> 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);
>
> return status;
> }
>


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

Reply via email to