Re: GObject - problem, as usual
- From: Lance Dillon <riffraff169 yahoo com>
- To: gtk-app-devel-list gnome org
- Subject: Re: GObject - problem, as usual
- Date: Tue, 1 Aug 2006 03:46:12 -0700 (PDT)
If I understand the problem correctly, you need to call the ancestor method's manually (regardless of whether
it is a finalize methoed or anything else). There is s section on it in the gobject documentation:
http://developer.gnome.org/doc/API/2.0/gobject/howto-gobject-chainup.html
----- Original Message ----
From: Tomasz Jankowski <tomcioj gmail com>
To: gtk-app-devel-list gnome org
Sent: Tuesday, August 1, 2006 6:10:15 AM
Subject: GObject - problem, as usual
Hi!
I'm writing some application based on GObject and I have problem when I'm
trying to destroy object. I have two object A and B, A derives from GObject
and B derives from A. I declared my own finalize methods for both objects,
but when I'm destroying B object only B finalize function is executed. When
I remowe B finlize function declaration from B_class_init () A finalize
function is executed normaly. Why B finalize method overrides A finalize
method and what should I do to remoe this overriding? Maybe some parts od my
code will be helpful:
GType A_get_type (void) {
/*PRINT_DBG_IN_FUN_NAME*/
static GType type = 0;
if (type == 0) {
static const GTypeInfo info = {
sizeof (AClass),
NULL, /* base_init */
NULL, /* base_finalize */
A_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (A),
0, /* n_preallocs */
NULL /* instance_init */
};
type = g_type_register_static (G_TYPE_OBJECT,
"AType",
&info, 0);
}
return type;
}
GType B_get_type (void) {
/*PRINT_DBG_IN_FUN_NAME*/
static GType type = 0;
if (type == 0) {
static const GTypeInfo info = {
sizeof (BClass),
NULL, /* base_init */
NULL, /* base_finalize */
B_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (B),
0, /* n_preallocs */
NULL /* instance_init */
};
type = g_type_register_static (A_TYPE,
"BType",
&info, 0);
}
return type;
}
static void B_class_init (gpointer g_class,
gpointer class_data)
{
PRINT_DBG_IN_FUN_NAME
GObjectClass *class = G_OBJECT_CLASS (g_class);
GParamSpec *spec;
g_type_class_add_private (class, sizeof (BPrivate));
class->constructor = B_constructor;
class->dispose = B_dispose;
class->finalize = B_finalize;
class->set_property = B_set_property;
class->get_property = B_get_property;
/* other code */
}
static void A_class_init (gpointer g_class,
gpointer class_data)
{
PRINT_DBG_IN_FUN_NAME
GObjectClass *class = G_OBJECT_CLASS (g_class);
GParamSpec *spec;
class->finalize = A_finalize;
class->set_property = A_set_property;
class->get_property = A_get_property;
/* other code */
}
I changed objects names, to make it more legible. PRINT_DBG_IN_FUN_NAME is a
macro, which display function name in console. Here is otput of running
'g_object_unref (g_object_new (A_TYPE, NULL))'. This is program output:
Function: A_class_init
Function: B_class_init
Function: B_constructor
Function: B_dispose
Function: B_finalize
I noticed, that in both *_class_init fnctions I use GObjectClass to declare
finalize, constructor etc. functions on it, is this main reason of my
problem?
--
Pozdrawiam!
Tom
_______________________________________________
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]