Re: [gtk-list] Re: Gtk programming style/advice
- From: Andy Connor <amc50 eng cam ac uk>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: Gtk programming style/advice
- Date: Mon, 11 Oct 1999 10:15:26 +0000
Havoc Pennington wrote:
>
> What problems are you having? Are some widgets destroyed while you still
> have pointers to them?
>
Not too sure what is going on as yet.
I have a fairly complicated GUI, so rather than create all the widgets
in one function, I want to split the creation into a number of functions
- I know that some of the contents will change and this will make it
easier for me to maintain.
Essentially, I have a 3x3 table, each cell of which contains more
widgets. One, for example, contains a scrolled window that contains a
CTree. Another contains a set of toggle buttons, the state of which will
effect the contents of the CTree.
Everything works fine if I create all the widgets in one function.
However, if I start to split it up and use a structure then it falls
over almost straight away. Below is the start of the code, which seg
faults when it tries to create the tree within the main window.
Any comments appreciated.
Andy
--
#include <gtk/gtk.h>
/* Create structure of widgets */
typedef struct{
GtkWidget *window;
GtkWidget *table;
}AllWidgets;
/* Function prototypes */
static void CreateMainWindow(AllWidgets *);
static void CreateTable(AllWidgets *);
/* Main function : contains a number of sub functions that create
widgets */
int main(int argc, char *argv[]){
AllWidgets *everything;
gtk_init(&argc,&argv);
CreateMainWindow(everything);
CreateTable(everything);
gtk_main();
return 0;
}
static void CreateMainWindow(AllWidgets *everything){
/* Make one widget in structure the top level window */
/* This works fine */
everything->window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize(everything->window,400,250);
gtk_container_set_border_width (GTK_CONTAINER(everything->window), 5);
gtk_signal_connect (GTK_OBJECT(everything->window),
"delete_event",GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_widget_show(everything->window);
}
static void CreateTable(AllWidgets *everything){
/* Make one widget in structure the table */
/* This cause a segmentation fault */
everything->table=gtk_table_new(3,3,FALSE);
gtk_container_add(GTK_CONTAINER(everything->window),everything->table);
gtk_widget_show(everything->table);
}
--
Andy Connor
Research Associate, Cambridge Engineering Design Centre
http://www.cus.cam.ac.uk/~amc50/home.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]