passing widgets to functions and back
- From: Aristidas Vilkaitis <A Vilkaitis aaa am lt>
- To: gtk-app-devel-list gnome org
- Subject: passing widgets to functions and back
- Date: Mon, 13 Jun 2005 13:53:34 +0300
Good day,
   I am developing a frontend for a modeling system and I have a severe 
problem concerning widget passing.
   Basicaly, the problem is simple. I have several notebook pages full 
of frames(which, in turn, are full of widgets). Each of these pages has 
n widgets storing different data(mostly spin buttons and entries). Once 
a button is pressed, the program should take all the data out of those 
widgets and process it.
   Since a callback function only accepts one argument(a gpointer), so 
I go for a GList. However, all notebook pages(and frames) go into 
different functions and differenc source files. I tried to pass a GList 
as an argument to each of those functions and add widgets to it inside, 
however, when returning to the main function, it states that a glist is 
empty.
   So the question would be - how to pass widgets around all funtions 
in a mannor that each function would be able to access any widget necessary?
   A small example of the problem is illustrated here:
   #include <gtk/gtk.h>
#include <glib/glist.h>
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();
}
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.
Respectfully,
Aristidas
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]