Re: Dynamic adding childs to a treestore
- From: Kjell Ahlstedt <kjell ahlstedt bredband net>
- To: Kees Kling <ckling upcmail nl>
- Cc: gtkmm-list gnome org
- Subject: Re: Dynamic adding childs to a treestore
- Date: Thu, 10 May 2012 10:38:04 +0200
Due to typedefs Gtk::TreeIter = Gtk::TreeNodeChildren::iterator =
Gtk::TreeModel::iterator and Gtk::TreeRow =
Gtk::TreeNodeChildren::value_type = Gtk::TreeModel::Row.
The relation between Gtk::TreeIter and the Gtk::TreeRow that it's
supposed to point to is weird. If 'iter' is a Gtk::TreeModel::iterator,
then *iter is a reference to iter itself, cast to a
Gtk::TreeModel::Row&. I think the consequence is that you can't handle
the iterators returned from sourceTreeStore->append() the way you do.
'row' in sourceViewer::appendRow() will point to a temporary object
which is deleted when sourceViewer::appendRow() returns (possibly earlier).
I think you must store Gtk::TreeModel::Row objects instead of pointers.
That will mean some copying of Gtk::TreeModel::Row, but I don't think
you should worry too much about that being inefficient.
Gtk::TreeModel::Row is a fairly small object.
I've marked in your code where I think you should change it.
Kjell
2012-05-09 15:40, Kees Kling skrev:
Hi
I'm trying to build a Gtk::TreeStore object dynamically which is
filled with records from a mysql table
code I'm using to build the TreeStore:
+++++
for ( vector<mysqlpp::Row>::iterator it = result.begin(); it !=
result.end(); ++it) {
const Gtk::TreeModel::Row* runchild =
source->appendRow((string)it->at(0),it->at(1),NULL);
const Gtk::TreeModel::Row runchild =
source->appendRow((string)it->at(0),it->at(1),NULL);
// getting unique runtimes of the model
query = dbaseConnection->query();
query<<"select distinct basetime from modeldata where MID =
"<<it->at(1);
vector<mysqlpp::Row>runtime;
query.storein(runtime);
for (vector<mysqlpp::Row>::iterator itr = runtime.begin(); itr
!= runtime.end(); ++itr) {
const Gtk::TreeModel::Row* fcchild =
source->appendRow((string)itr->at(0), 0,
runchild );
const Gtk::TreeModel::Row fcchild =
source->appendRow((string)itr->at(0), 0, &runchild);
or
source->appendRow((string)itr->at(0), 0, &runchild);
}
}
+++++
In this part I'm calling the method appendRow, which is a method of my
TreeView object
+++++++++++++++++
const Gtk::TreeModel::Row* sourceViewer::appendRow(string name, int id,
const Gtk::TreeModel::Row sourceViewer::appendRow(string name, int id,
const Gtk::TreeModel::Row* parent ) {
const Gtk::TreeModel::Row* row;
const Gtk::TreeModel::Row row;
if ( parent == NULL ) {
//Creates a new row at the end of the top-level.
row = &(*(sourceTreeStore->append()));
row = *(sourceTreeStore->append());
} else {
//Creates a child list
row = &(*(sourceTreeStore->append(parent->children())));
row = *(sourceTreeStore->append(parent->children()));
}
row->set_value(sourceColumns.name,name);
row->set_value(sourceColumns.id,id);
row.set_value(sourceColumns.name,name);
row.set_value(sourceColumns.id,id);
return row;
}
++++++++++++++++++++
As long as my third parameter = NULL, thus not creating a child
everything is OK, but when adding a child I get a crash and the nect
error
gtkmm:ERROR:treeiter.cc:214:const Gtk::TreeNodeChildren&
Gtk::TreeRow::children() const: assertion failed: (!is_end_)
What is wrong here?????
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]