idlackage
idlackage

Reputation: 2863

Gtkmm TreeView: Accessing dynamically added columns

I'm currently doing this to add numCols columns to a TreeView (ColumnRecord columns):

Gtk::TreeModelColumn<Glib::ustring>* c;
for( int i = 0; i < numCols; i++ ) {
    c = new Gtk::TreeModelColumn<Glib::ustring>();
    columns.add(*c);
    list.append_column(titles[i], *c);
    iss.clear();
}

To get an element at a certain row and column with a preset ColumnRecord, I would do something like Gtk::TreeModel::Row row; row[columns.c1] = blah. Now that the columns aren't named however, how will I access them?

Upvotes: 0

Views: 701

Answers (1)

Mark
Mark

Reputation: 108507

First, you have a potential memory leak here. You are newing up a TreeModelColumn with what looks like no way to ever delete it. With a widget that lasts the life time of the GUI this may not be a big deal. Another option is to use gtkmm's manage capabilities and let it worry about the memory.

Second, to address your problem, the way I've handled this scenario in the past was to collect my TreeModelColumn pointers into a std::vector or std::map so I access them later.

Upvotes: 1

Related Questions