load data from database to tree view
-
wrote on 9 Feb 2022, 12:56 last edited byThis post is deleted!
-
wrote on 9 Feb 2022, 14:36 last edited by
can anyone help ?
-
@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. -
wrote on 10 Feb 2022, 08:22 last edited by
@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
wrote on 10 Feb 2022, 08:34 last edited by JonB 2 Oct 2022, 08:41@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
-
wrote on 10 Feb 2022, 08:40 last edited by
Thanks for your interest, I'll look into them :)
1/6