Re: [gtk-list] Re: what's the opposite of the destroy signal?



jca wrote:
> 
> Havoc Pennington wrote:
> 
> > For the benefit of the original poster - the alternative to _new() is
> > that everything is supposed to happen in _init(), and then if you need
> > more information to set up the widget (stuff that traditionally would
> > be arguments to _new()), they should be settable via object arguments.
> >
> > So then you can create widgets with gtk_widget_new(), similar to the
> > way you create canvas items.
> 
>   What is an example of an _init callback?
> 
>   This is how I'm trying to get it to work:
> 
>   widget is created
>   data is created and added to widget with gtk_widget_set_data.
> .  .  .
> 
>   on configure_event, data is accessed again and again
> .  .  .
> 
>   on widget-destroy,
>   data is freed
>   widget is destroyed.

I think you should be using gtk_object_set_data_full().

This is the same as gtk_object_set_data() except you also pass it
a function to call to free the data when the object is destroyed
(or when the data is replaced by new data).

So the data is always freed automatically, and you don't need to
worry about memory leaks so much.


Note that you are free to edit the main() function output by Glade
so you can set the data there if you want, e.g.

  window1 = create_window1 ();
  gtk_object_set_data_full (GTK_OBJECT (window1), "my-data",
		            my_data_struct, my_func_to_free_data_struct);
  ...

Damon




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]