Results 1 to 2 of 2

Thread: Qtreeview from database(sqlite)

  1. #1
    Join Date
    Jun 2014
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Qtreeview from database(sqlite)

    hi I am new user qt5
    (I am .net csharp developer)

    I cant find example; Qtreeview(Qtreewidgets) fill from database.

    Is there any one know; where can I find this example.

    my database table like this

    ID; ParentID; Name; Category

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qtreeview from database(sqlite)

    SQL tables are usually placed in a QSqlTableModel and displayed in a QTableView. If you want your table displayed as a tree instead, then you will have to create a custom QAbstractItemModel around your SQL data and implement the index(), parent(), data(), rowCount(), and columnCount() methods correctly for it.

    The easiest way to do this is to create a C++ - based tree for your SQL results. You will have to build this tree manually by inserting each result row at the proper place in the tree based on the ID / ParentID relationships. Then, for each QModelIndex you create in your index() method, you set the QModelIndex::internalPointer() to the node in your C++ tree where the row can be found.

    You can't use QSqlTableModel or any of the related models because they all are based on the assumption that the data is a table, not a tree. The difference between a tree and a table is that for a table, the parent() method always returns an invalid QModelIndex. For a tree, only the top-most node returns an invalid index.

    For examples, try this link.

Similar Threads

  1. get data from sqlite database
    By bibhukalyana in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 12th June 2013, 12:20
  2. Sqlite Database
    By sabbu in forum Qt Programming
    Replies: 5
    Last Post: 16th May 2011, 13:07
  3. sqlite database problem
    By palinko1111 in forum Qt Programming
    Replies: 3
    Last Post: 4th May 2011, 07:04
  4. Use QT to set password for SQLITE database. help...!
    By Kevin Hoang in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2010, 07:28
  5. SQLITE database problems
    By phoenix in forum Newbie
    Replies: 3
    Last Post: 30th April 2007, 21:38

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.