PDA

View Full Version : how to use QTreeView with Database model



mikro
13th April 2006, 08:17
sorry if this is suppossed to be obvious, but i only see examples on how to use the QTreeView with QDir. I would like to use the result of a DB-query. Could anyone please point me towards information what my data has to look like? i mean: do i need a column called parent and one called id or how does it work that the Tree knows how to use the data in the model?

wysota
13th April 2006, 11:07
Relation databases gather data in tabular form. There is no sense to use a tree with such data. You have to provide some parent-child structure, but you have to do that yourself, the database won't do that for you.

BTW. What do you mean by "use QTreeview with QDir" and that you want to use a database query with it?

mikro
13th April 2006, 13:12
i understand that i will have to structure my data in a way that it makes sense in a tree.
The data came in the form of
01|NULL|NULL|Text
01|01|NULL|Text
01|01|01|Text
01|01|02|Text

so it makes sense to show it in a Tree but i doubt that if i send a tablemodel with this data to the QTreeView Object it will be able to work with that.
Do i need to build a nested set or do i need to have a parent id in some column or how else do i need to prepare my data to give it to the tree?


btw: what i meant with the QDir was the QDirModel which is always used to explain the QTreeView, as in http://doc.trolltech.com/4.0/qtreeview.html
and no i don't want to use this i hope to be able to use a QSqlQueryModel or something like that.

wysota
13th April 2006, 16:12
You should be able to do this quickly using a two layered model. Lower layer should be QSqlTableModel or QSqlQueryModel and on top of that you'd have to implement a proxy model which will map indexes from the sql model to a tree structure (see docs for the proxy model for details).