Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sql Tree Model/View
Forum Updated to NodeBB v4.3 + New Features

Sql Tree Model/View

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Seba84
    wrote on last edited by
    #1

    Hello all,

    I have a SQL table (SQLite) with the following structure:
    @CREATE TABLE filters (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(30), key VARCHAR(30), parent INTEGER, FOREIGN KEY(parent) REFERENCES filters(id))@

    There is a column "parent" which indicates the parent of each item. I would like to load it in a QTreeView. I already get all the data from a QSqlTableModel but the table is flat, meaning with no parent-child relationship. How can I make this happen?

    Thanks in advance!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      For that you would need a proxy that will create the proper hierarchy based on your table model content. Or maybe make your own model that will query the database and build the structure

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Seba84
        wrote on last edited by
        #3

        OK, thank you. I will check both solutions.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved