GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Sep 20, 2014 3:57 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 
Offline
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 ?
[code=]

#include <gtk/gtk.h>
void emit_destroy_signal(GtkWidget *widget,gpointer data)
{
gtk_main_quit();
}
void emit_my_signal(GtkWidget *widget,GtkWidget *window)
{
g_signal_emit_by_name(G_OBJECT(window),"destroy");
}

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");
gtk_container_add(GTK_CONTAINER(window),button);
g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(emit_destroy_signal),NULL);
g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(emit_my_signal),(gpointer)window);
gtk_widget_show_all(window);
gtk_main();
return 0;
}

[/code]


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

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

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: http://library.gnome.org/devel/gobject/stable/chapter-gobject.html (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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 06, 2009 2:42 am 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
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.


Top
 Profile  
 
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: Google [Bot] and 1 guest


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