GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

accessing children widgets

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
clinisbut
Familiar Face


Joined: 10 Apr 2008
Posts: 19

PostPosted: Tue Apr 15, 2008 3:25 pm    Post subject: accessing children widgets Reply with quote

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: (C++)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

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?
Back to top
Wolfgang
GTK+ Geek


Joined: 05 Feb 2008
Posts: 53

PostPosted: Wed Apr 16, 2008 6:19 am    Post subject: Reply with quote

Child widgets will be destroyed automatically with theyr parent... Isn't it?
Back to top
clinisbut
Familiar Face


Joined: 10 Apr 2008
Posts: 19

PostPosted: Wed Apr 16, 2008 6:55 am    Post subject: Reply with quote

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
Back to top
Wolfgang
GTK+ Geek


Joined: 05 Feb 2008
Posts: 53

PostPosted: Wed Apr 16, 2008 7:02 am    Post subject: Reply with quote

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?
Back to top
clinisbut
Familiar Face


Joined: 10 Apr 2008
Posts: 19

PostPosted: Wed Apr 16, 2008 7:24 am    Post subject: Reply with quote

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?
Back to top
Wolfgang
GTK+ Geek


Joined: 05 Feb 2008
Posts: 53

PostPosted: Wed Apr 16, 2008 7:28 am    Post subject: Reply with quote

You may use timer or idle-function, must work.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP