Re: gtk_object_set_data_full



gtk_object_set_data_full() will not make the
GTK_OBJECT(tree_view) a "child" of the main_window.

if you increment the reference count before 
gtk_object_set_data_full() then your code is safer.

eg.

widget = create widget;

g_object_set_data_full( another_object, widget )

destroy(widget)

GTK_WIDGET(g_object_get_data(another_widget))->member_of_struct

will seg fault.


So; the widget will not be destroyed untill every reference is
decremented.


PS.
        To answer the original question:
get the code that generated the library you're
using and have the function prototypes handy.

grep "function" `find src/ -name "*.[ch]"` 

it's alot easier than looking through a manual
(well I guess thats a matter of opinion but the
possibility is definitly an advantage when 
working with open source libraries)


Cheers
        -Tristan


drl22 cornell edu wrote:

Two little changes, you need to cast the 4th argument,
and gtk_object_ref returns void :-P.  Try this:

gtk_object_ref(GTK_OBJECT(tree_view));
gtk_object_set_data_full(
  GTK_OBJECT(main_window),
  "tree_view",
  GTK_OBJECT(tree_view),
  (GtkDestroyNotify)gtk_object_unref
);

That works nicely!

Anybody know why these ref/unrefs are necessary when
you add a child widget pointer to the parent widget?  I
know glade-generated code puts them in, so I do too,
but I don't understand them.

The child widget will be destroyed when the parent
widget is destroyed, so the parent's object data will
be inaccessible, right?  Am I missing something?

-Dan

Quoting Collin Starkweather
<collin starkweather collinstarkweather com>:

I'm very new to Gtk and not so hot with C, so please
bear with me.

I'm trying to set data using gtk_object_set_data_full
() to keep track of
some child widgets of my main window.  I'm using the
Gnome 1.x
libraries.

To do so, I'm trying something like

  gtk_object_set_data_full(
    GTK_OBJECT(main_window),
    "tree_view",
    gtk_object_ref(GTK_OBJECT(tree_view)),
    gtk_object_unref
  );

where tree_view is a GtkTree widget and which is
consistent with an
example I saw in a mailing list somewhere.

I'm getting an error:

  passing arg 4 of `gtk_object_set_data_full' from
incompatible pointer
type

Unfortunately, I can't find any documentation for
gtk_object_set_data_full other than the prototype in
the generic API
documentation such as


http://developer.gnome.org/doc/API/2.0/gtk/gtkobject.htm
l

which seems like it may be helpful if I had alot more
experience in Gtk
and/or C.  A bit of a chicken-and-egg problem there.

There's also no mention of it I can find in the book
I'm using, SAMS
"Teach Yourself Gtk+ Programming in 21 Days."  (I
know, I know, it's
probably not the most comprehensive manual out there,
but I'm just
learning.)

Any suggestions would be appreciated.

-Collin

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~
Collin Starkweather
http://www.collinstarkweather.com

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-
list


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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