Results 1 to 16 of 16

Thread: Populate QTreeView from database

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Populate QTreeView from database

    Hi,

    I am trying to fill a Treeview from a database source. I need to be able to manipulate treeview items and sync this with database. As far as i can understand , best (but not easiest) way is to use QAbstractProxyModel and implement maptoSource and mapfromSource functions. But i couldnt find a single example for doing this on a treeview.

    A starting point:

    Qt Code:
    1. QModelIndex TagChannelTreeModel::mapFromSource(const QModelIndex &sourceIndex) const
    2. {
    3. // root
    4. if (!sourceIndex.isValid())
    5. return QModelIndex();
    6.  
    7. //what to do here
    8. int col = sourceIndex.column();
    9.  
    10. return createIndex(sourceIndex.row() , sourceIndex.column());
    11. }
    To copy to clipboard, switch view to plain text mode 

    Here what should i do if column is other than "0"(Top level item) and i want to add this index as a child to parent(column 0 item) ? A small snippet would be appreciated :-)

    Thanks in advance...
    Last edited by yagabey; 22nd November 2014 at 14:07.

Similar Threads

  1. Qtreeview from database(sqlite)
    By cengiz3519 in forum Qt Programming
    Replies: 1
    Last Post: 4th June 2014, 23:42
  2. QTreeView & Sql Database.
    By gcain in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2013, 05:56
  3. Replies: 6
    Last Post: 20th February 2012, 10:59
  4. QTreeView and database
    By langziyang in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2010, 08:19
  5. using QTreeView with a Database model
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2007, 23:29

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.