Hello,
I’m trying to manually create a GListStore, by using my own row structure, by trying to do what Emanuelle says in How to use GListStore by creating my own “GObject” object
I think I did what it was said in the GObject tutorial GObject – 2.0: GObject Tutorial, everything was fine, until when I tried to do:
GListStore *root = g_list_store_new(MODELE_VIEWER_TYPE_DATA);
ModeleViewerData * g1 = g_object_new (MODELE_VIEWER_TYPE_DATA, NULL);
g_list_store_append(root, g1);
I go this error on the last instruction: “g_object_ref: assertion ‘!object_already_finalized’ failed”.
I checked “G_OBJECT(g1)->ref_count” and it gives me 0, so I guess it was the reaon of this error after I checked the source code of GObject.c
I tried to trick it by calling “g_object_ref(g1)” just before, by hoping that it will increase to “1” but I have same error" g_object_ref: assertion ‘!object_already_finalized’ failed"
In my “.h” file:
G_BEGIN_DECLS
#define MODELE_VIEWER_TYPE_DATA (modele_viewer_data_get_type ())
G_DECLARE_FINAL_TYPE (ModeleViewerData, modele_viewer_data, MODELE_VIEWER, DATA, GObject)
ModeleViewerData *modele_viewer_data_new (const char * col1, const char * col2, const char * col3, const char * col4);
G_END_DECLS
in my .c file
struct _ModeleViewerData
{
GObject *parent;
gchar *column1;
gchar *column2;
gchar *column3;
gchar *column4;/* Class virtual function fields. */ void (* open) (ModeleViewerData *modeleViewerData, GError **error); /* Padding to allow adding up to 12 new virtual functions without * breaking ABI. */ gpointer padding[12];
};
struct _ModeleViewerDataClass
{
GObjectClass parent_class;
};
G_DEFINE_FINAL_TYPE (ModeleViewerData, modele_viewer_data, G_TYPE_OBJECT)
ModeleViewerData*
modele_viewer_data_new (const char * col1, const char * col2, const char * col3, const char * col4)
{
return g_object_new (MODELE_VIEWER_TYPE_DATA,
“column1”, col1,
“column2”, col2,
“column3”, col3,
“column4”, col4,
NULL);
}
static void
modele_viewer_data_init (ModeleViewerData *self)
{
g_print(“modele_viewer_data_init IN… \n”);
//g_object_ref(self);/* self->column1 = g_alloca0(50); self->column2 = g_alloca0(50); self->column3 = g_alloca0(50); self->column4 = g_alloca0(50); */ // GObjectClass *mvdClass = G_OBJECT_CLASS (modele_viewer_data_parent_class); //ref_count_init(G_OBJECT(self)->ref_count); // g_ref_count_init(G_OBJECT(self)->ref_count);
}
I also have the following functions implemented:
modele_viewer_data_cla ss_init
modele_viewer_data_constructed
modele_viewer_data_finalize
modele_viewer_data_dispose
modele_viewer_data_get_property
modele_viewer_data_set_property
Do you know why it doesn’t want to put ref_count to 1 ?
I spent all my nights for many days to figure out what’s wrong, and I don’t find any example on internet, but I’m tired now, so I need your help.
Thanks