I have a little problem I am trying to figure out, I am working on a QT app that is using the QTreeView and I have a bunch of categories which have children, so they look like
Parent 1
Parent 2
- Child 1
- Child 2
Parent 3
and so on and so forth, so in my database I have rows which have all the regular details (name, id, date created, etc) and the ones which are children have their parent specified (so pid=parent row id). I then loop over then using the standard QSqlQuery stuff. But the problem I am running into is this...
Items are added to the treeview by QStandardItem* item = new QStandardItem(icon, name);
and then appending the row model->appendRow(item);
but my children need to call parentitem->appendRow(item);
so the QStandardItem* item
of the parent. But how can I find out what that is without storing every single item
?
Moral of the story is, is there a way to do one of the following that won't destroy performance.
- Store the
QStandardItem* item
in an array that I could reference the parent in the childs loop? - Assign an ID or something to
QStandardItem* item
which I could then reference when adding a child. - Generate a TreeView model from an array, where the children array elements get added as children?
- Something else I haven't thought of...
I can't seem to find any good examples of QTreeView with children from a database.