title: How do I quit a gtk application from a button click?
body: <p>Im trying to quit an application from a button click. What I'm currently doing Segfaults. </p>
  
  <p>I have tried calling <code>g_application_quit(G_APPLICATION(app));</code> in main it still segfaults</p>
  
  <p>Calling <code>gtk_widget_destroy(window);</code> also segfaults</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;gtk/gtk.h&gt;
  void activate(GtkApplication* app, gpointer data)
  {
      GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_application_add_window(app, GTK_WINDOW(window));
      GtkWidget *button = gtk_button_new_with_label("Button");
      void shutdown()
      {
          g_application_quit(G_APPLICATION(app));
      }
      g_signal_connect(GTK_BUTTON(button), "clicked", G_CALLBACK(shutdown), NULL);
      gtk_container_add(GTK_CONTAINER(window), button);
      gtk_widget_show(button);
      gtk_window_present(GTK_WINDOW(window));
  }
  
  int main (int argc, char *argv[])
  {
      GApplicationFlags flags = G_APPLICATION_FLAGS_NONE;
      GtkApplication *app = gtk_application_new("com.devab.daw", flags);
      GApplication *gapp = G_APPLICATION(app);
      g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
      g_application_run(gapp, argc, argv);
      g_object_unref (app);
      //g_application_quit(G_APPLICATION(app));
      return 0;
  }
  </code></pre>