How to create a db and display it into a treeview? (Advice)



  • Hello!
    I can not decide or convince myself which approach I should learn or inspect.
    In genereal I have an app which has a settings page with a strcuture of a tree.
    Like:
    It is rough example of what I would like to implement.

    • car
      • speed - 20
      • weight - 100
    • bycicle
      • grils bike
        • color - red
        • color - pink
      • boys bike
        • color - black
        • color - green

    All that data I want to put into a db. Than display it and edit.

    What I have for now are TreeModel derived from QAbstractItemModel and TreeNode. Data for my TreeModel I populate manually
    like: TreeModel.nodesList.append("bike", "red") etc.
    But I would like to load the data from the db and put it into a TreeNode.
    Please put me in a right direction. Advice on how to make it would be great!
    Thank you.


  • Lifetime Qt Champion

    Hi,

    A QSqlTableModel with a QAbstractProxyModel comes to mind. The former to get the data from your database, the later to turn in into a tree structure.

    Otherwise, you can use QSqlQuery to extract the data from your database and put it in your TreeModel which is the fast and easy way.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.