Results 1 to 2 of 2

Thread: QTreeView & Sql Database.

  1. #1
    Join Date
    Jan 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QTreeView & Sql Database.

    Is the only way to display a QTreeView to loop through a record set and manually construct a hierarchical model?

    So far the only examples I can find for QTreeView are pretty much manually constructed. What if I wanted changes to the data to be displayed in other widgets or written back to the data source?

    All I can find are examples like this:
    Qt Code:
    1. QStringList jobslist = jobs();
    2. m_jobsmodel = new QStandardItemModel;
    3.  
    4. QStringList headerLabels;
    5. headerLabels << "Date" << "UUID" << "Assigned" << "Due Date" << "Status";
    6. m_jobsmodel->setHorizontalHeaderLabels(headerLabels);
    7.  
    8. foreach(const QString& job, jobslist) {
    9. QList <QStandardItem *> jobItem;
    10. jobItem << new QStandardItem(QIcon(":/png/64x64/accept.png"), jobTitle(job));
    11.  
    12. QStringList tasks = tasksByJob(job);
    13. foreach(const QString& task, tasks) {
    14. QList<QStandardItem*> items;
    15. items << new QStandardItem(QIcon(":/png/64x64/remove.png"), taskTitle(task));
    16. items << new QStandardItem(task);
    17. items << new QStandardItem(taskAssignee(task));
    18. items << new QStandardItem(taskDue(task));
    19. items << new QStandardItem(taskStatus(task));
    20.  
    21. jobItem.at(0)->appendRow(items); // append child items to top-level item
    22. }
    23. m_jobsmodel->appendRow(jobItem);
    24. }
    To copy to clipboard, switch view to plain text mode 

    I am aware that data in an sql table is 2D, but surely there is a mechanism to display 2D data in a hierarchical form without having to construct a copy of what is in the database?

    Thanks for your advice in advance.

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView & Sql Database.

    There are QSqlTableModel , QSqlRelationalTableModel and other related classes. However, they follow more of a master detail concept than a tree like structure.

Similar Threads

  1. Replies: 2
    Last Post: 27th August 2012, 03:27
  2. QTreeView and database
    By langziyang in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2010, 08:19
  3. using QTreeView with a Database model
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2007, 23:29
  4. how to use QTreeView with Database model
    By mikro in forum Newbie
    Replies: 3
    Last Post: 13th April 2006, 16:12
  5. Replies: 8
    Last Post: 7th March 2006, 13:40

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.