Re: Adding a widget (in code) to a Glade-derived window



Stupid me... :-(
It works now!
Thanks for your (quick) answer.�Sorry for wasting your time.


On Tue, May 24, 2011 at 12:24 PM, Krzesimir Nowak <qdlacz gmail com> wrote:
2011/5/24 Samuel Pelaez <samuel pelaez gmail com>:
> Hi,
> I think I'm missing something obvious here...
> I create a Gtk::Window with a Gtk::VBox in it using Glade. Then in my code I
> create a Gtk::Label and try to pack_start it into my Builder-instantiated
> window. But nothing is shown but an empty window!!
> Here is the sample code, which does not show any label, as I would expect...
> #include <gtkmm.h>
> #include <gtkglmm.h>
> class gui_main : public Gtk::Window
> {
> public:
> gui_main( BaseObjectType*, const Glib::RefPtr<Gtk::Builder> & );
> ~gui_main(){}
> };
> gui_main::gui_main(
> BaseObjectType*cwindow,
> const Glib::RefPtr<Gtk::Builder> & builder )
> :Gtk::Window( cwindow )
> {
> Gtk::VBox * vbox;
> builder->get_widget( "vbox1", vbox );
> Gtk::Label label1( "blah1" );
> vbox->pack_start( label1, true, true, 10 );
> label1.show();
> //show_all_children();
> //show();
> }
> #include <gtkmm/main.h>
> int main( int argc, char**argv )
> {
> � � Gtk::Main kit( argc, argv );
> � � Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
> � � refBuilder->add_from_file( "/home/samuel/test_window.glade" );
> � � gui_main* gui;
> � � refBuilder->get_widget_derived( "window1", gui );
> � � kit.run( *gui );
> � � return 0;
> }
> (Of course in my real program I won't be packing a label, but some custom
> widget, which inherits from Gtk::GL::DrawingArea...)
> Best regards
> Samuel
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
>

Sorry for double post - I forgot to CC the list.

Sure you are missing something obvious - Gtk::Label is destroyed on
constructor quit - it is an automatic variable. Better try doing
something like:

Gtk::Label* pLabel (Gtk::manage(new Gtk::Label("blah1")));
vbox->pack_start( *pLabel, true, true, 10 );



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