GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 01, 2014 10:20 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: accessing children widgets
PostPosted: Tue Apr 15, 2008 3:25 pm 
Offline
Familiar Face

Joined: Thu Apr 10, 2008 1:43 pm
Posts: 19
I'm trying to figure out how to access a list of child widgets of a widget.
Specifically GtkTable child widgets to destroy them with GtkTable itself.

I'm not using Glade, I'm creating each widget "manually" from code and I can't store a pointer of each one (well, actually I could but I don't need this pointers except for its destruction after using them).

I found the function gtk_container_get_children and I tried to use it.

The structure I have is next:
GtkTable
|-each cell has:
|-vbox
|-DrawArea
|-hbox
| |-label
| |-entry
|
|-hbox
| |-label
| |-entry


Then, at user action I need to erase the complete table and create the same structure (with diferent values).

This is the code I wrote to try to destroy gtktable and its children
Code:
if( table!=NULL )
{
   GList* children = gtk_container_get_children( GTK_CONTAINER( table ) );
   guint num_child = g_list_length( children );
   cout << "NUM CHILDREN="<<num_child<<endl;
   int i=0;
   while( i<num_child )
   {
      cout << "deleting child n:"<<i<<endl;
      gtk_widget_destroy( GTK_WIDGET( children->data ) );
      children = children->next;
      ++i;
   }

   gtk_widget_destroy( GTK_WIDGET( table ) );
}


But the first time the code tries to erase throws me a lot of asserts:

gtk_box_pack_start: assertion `child->parent==NULL´ failed.

Maybe has to do with that if( table!=NULL ) ? Is it ok the way I check if table already exists?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 6:19 am 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
Child widgets will be destroyed automatically with theyr parent... Isn't it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 6:55 am 
Offline
Familiar Face

Joined: Thu Apr 10, 2008 1:43 pm
Posts: 19
I dont' know,
anyway I'm interested in learn how to acces child widgets 'cause I need to get the value of all those entry widgets


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 7:02 am 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
So, your code is correct, althow I'm using function g_slist_next for GSList items enumeration.
In which moment this code snippet is executed? Is variable table global and initialized as NULL?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 7:24 am 
Offline
Familiar Face

Joined: Thu Apr 10, 2008 1:43 pm
Posts: 19
This code is executed in a signal callback.
Actually I simplified the code so table is member of a class, this class is passed as gpointer argument to function callback.

So when I wrote "table" actually is "control->table".
Anyway, I think I solved the problem... but don't know what I touch XD.
I think I had a name conflict between function variables and class member variables. Also I deleted that widget by widget deletion and I delete the entire gtktable at once.


I have another question, but is about progressBars, do I need to open a new thread?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 7:28 am 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
You may use timer or idle-function, must work.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 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