Re: [gtk-list] Re: Trying to add widgets via callback



On Tue, Feb 24, 1998 at 12:40:29AM +0100, Tim Janik set free these words:
> On Mon, 23 Feb 1998, Toshio Kuratomi wrote:
> 
> > Hello.
> > I'm trying to add widgets into a vbox when a user clicks on a button.
> > Unfortunately, all I'm getting so far is SegV.  I've run the program
> > through gdb and I think I'm having problems passing my vbox (pointer)
> > into the callback, but I'm not sure of the remedy.
> > If anyone could help me, I'd be most appreciative.
> > 
> > Here is the code I'm using:
> > [][][][][][][][]
> > 
> > GtkHandleBox *
> > newEntry (char *note) {
> > 
> >  GtkWidget *entry_area;
> >  GtkWidget *container;
> > 
> >  container = gtk_handle_box_new();
> >  entry_area = gtk_entry_new();
> > 
> >  gtk_container_add(GTK_CONTAINER(container),entry_area);
> >  gtk_widget_show(entry_area);
> > 
> >  return GTK_HANDLE_BOX(container);
> > }
> > 
> > void
> > addEntry (GtkWidget widget,
> >           GtkBox **container_to_add_to) {
> 		   ^^^^^^^^^^^^^^^^^^^^^^
> 		   should be *container_to_add_to
> > 
> >  GtkWidget *entry_box;
> >  entry_box=newEntry(NULL);
> > #if 0
> > The next line is where I segV out.  At one point I was passing
> > container_to_add_to in as a GtkWidget * and then the segV occurred
> > in the casting function GTK_BOX(container_to_add_to)....
> > #endif
> >  gtk_box_pack_start(*container_to_add_to,entry_box,TRUE,TRUE,0);
> 		      ^^^^^^^^^^^^^^^^^^^^
> 		      should be (container_to_add_to)
> >  gtk_widget_show(entry_box);
> > 
> > }
> > 
> > GtkWindow *
> > newWindow (GtkHandleBox *initial_note) {
> > 
> > /* Define the basic necessities of a window. */
> >  GtkWidget *top_window;
> >  GtkWidget *vbox;
> >  GtkWidget *new_entry_button;
> > [snip]
> > 
> > /* Create the widgets that go into our program. */
> >  top_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  // Create Managed window
> >  vbox = gtk_vbox_new(FALSE,0);              // Create the layout box.
> >  new_entry_button = gtk_button_new_with_label("New Entry");
> > 
> >  gtk_signal_connect(GTK_OBJECT(top_window), "delete_event",
> >                     GTK_SIGNAL_FUNC(closeWindow), top_window);
> > 
> >  gtk_signal_connect(GTK_OBJECT(new_entry_button), "clicked",
> >                     GTK_SIGNAL_FUNC(addEntry), &vbox);
> 						 ^^^^^
> 						 should be (vbox), since
> vbox already is a pointer to your container, and the contents of
> &vbox will be lost after newWindow is left because the it is a stack
> variable.
> 
Okay.  That makes sense.  But the three changes don't make my problem
disappear.  I still get the same error in the same place.

Since vbox is a pointer to a container, will vbox disappear as well?  Do I
need to send a dereferenced vbox to my callback?  How do I manage that?
(gtk_signal_connect seems to expect a pointer as its fourth element).

-Toshio

-- 
badger    \\  "What's all this?  What's all this?"
@prtr-13    \\   -Mr. Banks, Mary Poppins
.ucsc.edu     \\=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

PGP signature



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