GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Aug 25, 2016 8:12 pm

All times are UTC

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: emit destroy signal
PostPosted: Mon Mar 30, 2009 2:58 am 
Familiar Face

Joined: Fri Sep 28, 2007 10:59 am
Posts: 46
hi . in my example program , when I want emit destroy signal after click button , I recive some warrning like this
test:16008): Gtk-CRITICAL **: gtk_style_detach: assertion `style->attach_count > 0' failed
, whats problem here ?
I can use some func like this g_signal_swapped
, but I want emit this signal with this way . how I can do it ?

#include <gtk/gtk.h>
void emit_destroy_signal(GtkWidget *widget,gpointer data)
void emit_my_signal(GtkWidget *widget,GtkWidget *window)

int main(int argc, char *argv[])
gtk_init(&argc, &argv);
GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget *button=gtk_button_new_with_label("emit window delete-event signal");
return 0;


 Post subject:
PostPosted: Mon Mar 30, 2009 9:41 am 
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia

Emitting "destroy" signal on last remaining top level window is bad idea, use gtk_widget_destroy function instead, which is a wrapper around that signal and does some things that ensure everything is in a consistent state throughout the destroy process.

And if you're curious enough to ask "Why is last top level window so special?", well, prepare for a rough ride on a roller coaster of GObject destruction process. Documentation about this can be found here: (the part that causes troubles for you is described with one paragraph inside those docs:
GObject docs wrote:
GObject's memory management model was designed to be easily integrated in existing code using garbage collection. This is why the destruction process is split in two phases: the first phase, executed in the dispose handler is supposed to release all references to other member objects. The second phase, executed by the finalize handler is supposed to complete the object's destruction process. Object methods should be able to run without program error (that is, without segfault :) in-between the two phases.

The main problem of your way is that when the top level window's GtkStyle is unreferenced and destroyed (since this is the last widget that was holding a reference to it), there is no default style anywhere to find (since we just destroyed it with previous call) which is usually attached to widget to go through the destruction process smoothly.

 Post subject:
PostPosted: Wed May 06, 2009 2:42 am 
Never Seen the Sunlight

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 323
Location: Fortress of solitude
Yeah, thanks for the tip :)

* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group