on cleaning up connection, my application crashes.
but connection is owned by the app, so this clean is not required , but is still falls into my while loop for clean up , cant seem to understand this bit.
#include <gtk/gtk.h>
GDBusConnection *connection=0;
static void activate (GtkApplication *app,gpointer user_data)
{
connection= g_application_get_dbus_connection (g_application_get_default ());
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_window_present (GTK_WINDOW (window));
}
int main(int argc, char *argv)
{
auto app = gtk_application_new (“org.gnome.Screenshot”, G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, “activate”, G_CALLBACK (activate), NULL);
auto status = g_application_run (G_APPLICATION (app), argc, argv);
while(G_IS_OBJECT(app))
{
cout<<"app"<<endl;
g_object_unref(app);
}
while(G_IS_OBJECT(connection)) //connection is owned by app, the app has been unref,
{ //this object should be cleaned as well
cout<<"connection"<<endl;
g_object_unref(connection); //it crashes
}
return 0;
}