Re: [gtkmm] GTKMM classes handling local variables



Ian,

Your _label gets destroyed when you leave the constructor
(MyClass::MyClass), because it's local.
That's probably why it is not desplayed.

You could either declare it in the class, or allocate it with new and use Gtk::Manage on the pointer:

This code should work:

MyClass::MyClass()
{
	Label *_label = Gtk::Manage( new Label("Hello World"));
	m_box.pack_start(*_label, PACK_SHRINK);
	show_all_children();
}


Ben

Hi all,
Maybe someone can help me with this, I have only been developing with
GTKMM for a little while so I am a little bit of a newbie.

Right here is a piece of example code:

class MyClass : public Gtk::Window
{
	public:
		MyClass();
		virtual ~MyClass();
	private:
		VBox m_box;
};

MyClass::MyClass()
{
	Label _label("Hello World");
	m_box.pack_start(_label, PACK_SHRINK);
	show_all_children);
}

MyClass::~MyClass()
{
}

Right what I cannot understand is why this program will compile but my
label will not be displayed? For some reason it will only work if I
declare my Label in the class definition... I don't see why it is not
working... :(

Ian

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list







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