Re: adding widget to vbox created by glade



On Sun, 2007-12-02 at 12:38 +0000, Robert Pearce wrote:
> On Sun, 2 Dec 2007, Gezim Hoxha <gezimetc shaw ca> wrote :
> >
> >So, now this code works:
> >       Gtk::VolumeButton *my1223 = new Gtk::VolumeButton;
> >       myvbox->pack_end(*my1223);
> >       my1223->show();
> >
> >but this doesn't:
> >       Gtk::VolumeButton my1223;
> >       myvbox->pack_end(my1223);
> >       my1223.show();
> >
> >and my question is, why doesn't this last code work?
> >
> Is this code in a function / method? Because if so the explanation is 
> simple. The second form creates a _local_ _temporary_ Gtk::VolumeButton 
> object and packs then shows it. And then the function / method 
> terminates and all local objects are destroyed, including the widget.
> 
> The first form makes the widget on the heap and only destroys a pointer 
> to it.

Thanks Robert, that makes sense. Still trying to wrap my head around the
GUI programming paradigm.

-Gezim



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