Re: Do widgets have to be members of class?
- From: Krzesimir Nowak <qdlacz gmail com>
- To: hokie54 <nick5449 yahoo com>
- Cc: gtkmm-list gnome org
- Subject: Re: Do widgets have to be members of class?
- Date: Tue, 15 Sep 2009 14:24:53 +0200
On Mon, 2009-09-14 at 20:00 -0700, hokie54 wrote:
> Forgive me for my ignorance, but I'm new to any sort of GUI development...
>
> I'm attempting to create a table with X labels inside of it. However, it
> seems as if I can not add items to the table that are not members of the
> class. For example this will NOT work:
>
> MainWindow.h
> public:
> MainWindow();
>
> protected:
> Gtk::Table my_table;
> };
>
> MainWindow.cc
> MainWindow::MainWindow() :
> my_table(2,2, true),
> {
> add(my_table);
> Gtk::Label label("LABEL");
>
> my_table.attach(label, 0, 1, 0, 1);
>
> show_all_children();
> }
>
>
> It seems as if making 'label' a protected member of MainWindow is the only
> way to make this work. Is there any way around this since I do not
> initially know how many labels I will need inside the table?
>
> Thanks
Your label in constructor has local scope, so after constructor finishes
its activity, label is destroyed. So yes, it has to be a member of your
class. Or have global scope, which is ugly.
If you don't know how many label will be inside, then use a vector or
list containing labels.
Krzem
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]