Re: passing widgets to functions and back



Aristidas Vilkaitis wrote:


It crashes with a coredump, appearantly since the glist is
empty(somehow the function a_table is not capable of modifying the list).

I'm quite new to C and GTK, so this may be very simple problem, but
i'm stuck in this place for a very long time. please help.

You're modifying the local copy of list in the a_table function, main()
never sees the modified value. The code must be something like this:

GtkWidget *a_table(GList **list)
{
 GtkWidget *table;
 GtkWidget *label;

 table = gtk_table_new(1, 1, FALSE);

 label = gtk_label_new("Sample text");
 *list = g_list_append(*list, label);
 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);

 return table;
}

int main(int argc, char *argv[])
{
 GtkWidget *window;
 GtkWidget *table;
 GtkWidget *label;
 GList *list = NULL;

 gtk_init(&argc, &argv);

 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

 table = a_table(&list);
 gtk_container_add(GTK_CONTAINER(window), table);
 gtk_widget_show_all(window);

 label = (GtkWidget *) g_list_nth(list, 0)->data;
 g_print("%s\n", gtk_label_get_text(GTK_LABEL(label)));

 gtk_main();

}


However, I haven't tried that.

-- 
Pain is a thing of the mind.  The mind can be controlled.
                -- Spock, "Operation -- Annihilate!" stardate 3287.2

Eduardo M KALINOWSKI
ekalin bol com br
http://move.to/hpkb





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]