PDA

View Full Version : QTreeView with results from an SQL query.



ederbs
16th October 2007, 02:41
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:



SqlQuery queryVtr;
queryVtr.exec("SELECT....");

QStandardItemModel *model = new QStandardItemModel(0, 3, this);

model->setHeaderData(0, Qt::Horizontal, QObject::tr("Viaturas"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Equipamentos"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Status"));

while (queryVtr.next())
{
QStringList setVtrModel = queryVtr.value(0).toStringList();
treeView->setModel(model);
}



Is there an quick way to do this?

edm

jpn
19th October 2007, 03:41
Why not use QSqlQueryModel?