GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Aug 28, 2016 10:23 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: GtkBuilder objects reference counting [long]
PostPosted: Fri Jan 27, 2012 10:20 pm 
Familiar Face

Joined: Tue Dec 13, 2011 2:36 pm
Posts: 5
Hi all.
I'm try to make an application with gtk-2.16.6 using Glade 3.6.6 with VC express 9.0.
All the sdk is installed from this setup: glade3-3.6.7-with-GTK+.exe

I'd like to make the gui part with Glade, and create a custom widget (often a container) which load the layout from glade file.

First I put the structure of the project.

Inside glade file
GtkVBox [name=sublayer1]
  GtkLabel [name=label1]
  GtkButton [name=button1]

I create the custom widget sublayer1 derived from a GtkFrame.
In sublayer1_init i load the sublayer1 from gladefile with

void sublayer1_init(SubLayer1 *self)
  GObject *object = gtk_builder_get_object(BUILDER, "sublayer1");
  gtk_widget_set(GTK_WIDGET(self), "child", object, NULL);  /* [1] */

GtkWidget *sublayer1_new()
  return gtk_widget_new(sublayer1_get_type(), NULL);

This happens.
I add the sublayer1 to a GtkHBox:
sublay = sublayer1_new();
gtk_box_pack_start(GTK_BOX(top), sublay, TRUE,TRUE, 0);

Inside the callback 'remove_layer' of a signal "clicked" I remove the sublay from GtkHBox.
Inside another callback 'add_layer' I readd sublay = sublayer1_new(); [2]

When I readd the sublayer1 the GtkVBox inside glade file has not children widgets.

I dump the GtkVBox tree before [1].
This is the result
GtkVBox  ref_count=2
  GtkLabel ref_count=2
  GtkButton ref_count=2
    GtkALignment ref_count=1
    GtkHBox ref_count=1
      GtkImage ref_count=1
      GtkLabel ref_count=1

Then I dump the parent for GtkLabel label1 and GtkButton button1
GtkLabel label1 parent=0084e000 ref_count=2
GtkButton button1 parent=0084e000 ref_count=2

After [2] I dump the sublayer1 tree
GtkVBox ref_count=2

and the parents are

GtkLabel label1 parent=00000000 ref_count=2
GtkButton button1 parent=00000000 ref_count=2

label1 and button1 has lost the parent.


There are function to add a reference for each childs of GtkVBox sublayer1 defined in the glade file?

If you run mainwind.exe from bin folder in the console you the read the behaviours.
I have to click Add1, Remove1, Add1.
After the second Add1 I can see only the GtkFrame.

Best regards,

File comment: All project.
The executable is in the folder "bin" [25.56 KiB]
Downloaded 126 times
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

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