Results 1 to 2 of 2

Thread: QTreeView with results from an SQL query.

  1. #1
    Join Date
    Sep 2006
    Location
    Rio de Janeiro, Brazil
    Posts
    44
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default QTreeView with results from an SQL query.

    Hi Friends,

    I am using the QTreeView class and the class model QStandardItemModel. I want to popluate the QTreeView with the results of the SQL query.

    I am trying something like this only shows one more record:

    Qt Code:
    1. SqlQuery queryVtr;
    2. queryVtr.exec("SELECT....");
    3.  
    4. QStandardItemModel *model = new QStandardItemModel(0, 3, this);
    5.  
    6. model->setHeaderData(0, Qt::Horizontal, QObject::tr("Viaturas"));
    7. model->setHeaderData(1, Qt::Horizontal, QObject::tr("Equipamentos"));
    8. model->setHeaderData(2, Qt::Horizontal, QObject::tr("Status"));
    9.  
    10. while (queryVtr.next())
    11. {
    12. QStringList setVtrModel = queryVtr.value(0).toStringList();
    13. treeView->setModel(model);
    14. }
    To copy to clipboard, switch view to plain text mode 

    Is there an quick way to do this?

    edm

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeView with results from an SQL query.

    Why not use QSqlQueryModel?
    J-P Nurmi

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.