Results 1 to 2 of 2

Thread: QSqlQueryModel and QTreeView

  1. #1
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QSqlQueryModel and QTreeView

    Hello. Tell me how to use QSqlQueryModel and QTreeView do something like this?:
    tree.jpg

    Depending on the value of field2 to set the level of the nesting tree. That is, as shown in the picture. Record with id = 3 must be embedded into the record with id = 2, because the value of field2 = 2. and so on.

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel and QTreeView

    Hi,

    I would:

    1. Use QSqlQuery to get the the full data of that table organized by field1.
    2. Browse through the records of the table. Each field1 will appear one after another and its parent field2 will be a previous field1
    3. Use a QList<QTreeWidgetItem *> items; to hold the total amount of items.
    4. Each record in the table will create a QTreeWidgetItem item.
    4.1 If the record does not have field2 then add item to items with no parent and attach the field1 value to the item (you can use setData for this)
    4.2 If the record has field2, search the current list of items looking for the value of field1, when fund use that item as parent for the new item the add it to items.
    5. When its finished you can set the items to the treeview with: ui->mytree->insertTopLevelItems(0, items);

    Good luck.
    Carlos.

  3. The following user says thank you to qlands for this useful post:

    oddytz1989 (28th February 2012)

Similar Threads

  1. QSqlQueryModel
    By StefanLatsch in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2010, 11:09
  2. Does 'QSqlQueryModel' have a bug?
    By nuntawat in forum Qt Programming
    Replies: 8
    Last Post: 6th April 2010, 17:45
  3. About QSqlQueryModel
    By vinny gracindo in forum Newbie
    Replies: 1
    Last Post: 11th December 2009, 22:27
  4. how to display QSqlQueryModel in QTreeView
    By mandal in forum Newbie
    Replies: 6
    Last Post: 2nd September 2009, 08:25
  5. QSqlQueryModel -> QTreeView
    By smrtak in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2008, 18:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.