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. Display data from two SQL Tables with QTreeView
Qt 6.11 is out! See what's new in the release blog

Display data from two SQL Tables with QTreeView

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.9k 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.
  • N Offline
    N Offline
    nicolae.rosia
    wrote on last edited by
    #1

    Hello,

    I am trying to create a model based on QAbstractItemModel to be used with QTreeView in order to display data contained in two SQL tables. The first table, Table1, has the rowId as primary key. The second table, Table2, has also a primary key and another field as foreign key which references Table1(rowId).
    As far as I understand, QAbstractItemModel::index returns an QModelIndex into which I embed data (internalPointer()) which I later use when QAbstractItemModel::data and QAbstractItemModel::parent are called.
    The problem is that the dataset is huge hence I cannot cache it and I would like to cache only the rows that are visible. Is there any way to know which rows are visible ?
    How would you approach this problem?

    Best regards,
    Nicolae Rosia.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Santosh Reddy
      wrote on last edited by
      #2

      Use two QSqlTableModels inside your custom QAbstractItemModel, and I don't think you need worry about cacheing the rows yourself, it will be taken care by QSqlTableModels

      SS

      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