Re: [gtkmm] Erasing TreeModel rows...
- From: Thomas Johansson <prencher prencher dk>
- To: Dennis Craven <linuxnewb rogers com>
- Cc: gtkmm-list gnome org
- Subject: Re: [gtkmm] Erasing TreeModel rows...
- Date: Thu, 26 Feb 2004 10:50:33 +0100
On tor, 2004-02-26 at 05:05, Dennis Craven wrote:
> Hey,
>
> I've been following the documentation and examples online and in the
> distribution. They are helpful, but a little unclear about removing rows
> from TreeModels. Here is the function that I have attempting to do the
> dirty work.
>
> void MyTreeView::deleteRow(Glib::ustring title)
> {
> Gtk::TreeModel::Children children = treestore->children();
>
> for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter
> != children.end(); ++iter)
> {
> Gtk::TreeModel::Row row = *iter;
> if (row[columns.m_col_name] == title) {
>
> ////
> // Segfaults on this erase line. "treestore" is declared as
> // Glib::RefPtr<Gtk::TreeStore> treestore;
> // and is a protected member of the MyTreeView class.
> ////
> treestore->erase(iter);
> break;
> }
> }
> }
>
> When execution gets to the point of failure (the erase statement), the
> iter is in fact valid and is at correct row. I can print out information
> stored on that row, this is why I'm certain. Execution does not get
> beyond that line.
>
> I've looked around for row removal examples, and had no luck. Anyone
> here have any pointers?
> Thanks.
> ~djc
As least when dealing with STL containers, you just have to increase the
iter, by taking the returned iter of erase, as such:
for (<sometype>::iterator it = <instance>.begin(); it !=
<instance>.end();)
{
if (something qualifies to be deleted) {
it = <something>.erase(it);
} else {
++it;
}
}
--
Thomas Johansson <prencher prencher dk>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]