load data from database to tree view
-
@Nevez said in load data from database to tree view:
can anyone help ?
Why so impatient?
The treeview you show above is not that easy. You have to build your tree model by your own. -
@Christian-Ehrlicher I know that too. However, I have no idea how to do this. Can you give some hint
-
@Christian-Ehrlicher I know that too. However, I have no idea how to do this. Can you give some hint
@Nevez
To create a hierarchical parent-child tree model you need two things from your data:- Some unique
id
column for every row. - A
parent_id
column in every row, whose value is the uniqueid
of some other row which is its parent.
You could store these as columns in your actual database
TABLE
s, or viaVIEW
s you create on the tables, or via yourSELECT
statement, as suitable. You can also impose a suitable QAbstractProxyModel on top of your SQL model to present the data hierarchically to theQTreeView
.Then you have the information to populate your data model/table view correspondingly.
I have not looked through it, but starting from Googling, say,
qt qsqldatabase qtreeview
, there is
https://stackoverflow.com/questions/53418180/populate-qtreeview-as-parent-and-child-nodes-from-database
https://forum.qt.io/topic/83982/populate-qtreeview-from-sql
https://www.qtcentre.org/threads/23698-how-to-display-QSqlQueryModel-in-QTreeView - Some unique