Re: Do widgets have to be members of class?



Am Dienstag, den 15.09.2009, 14:24 +0200 schrieb Krzesimir Nowak:

> 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.

Eeek, no.  Just use Gtk::manage() and container ownership:

    Gtk::Label *const label = new Gtk::Label("LABEL");
    table.attach(*Gtk::manage(label), 0, 1, 0, 1);

Personally, I use Gtk::manage() for widgets more often than not.  I do
not make widgets member of a class if the code does not need to access
it after construction.

--Daniel




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