PDA

View Full Version : Can a QSqlModel be converted to a QStandardItemModel



sgmurphy19
21st March 2008, 17:21
Is there a more straightforward way to convert a QSqlModel to a QStandardItemModelOther than:

qstandarditemmodel->insertRows(0, qsqlmodel->rowCount());
qstandarditemmodel->insertColumns(0, qsqlmodel->columnCount());
for(int c=0; c<qsqlmodel->columnCount(); c++)
{
qstandarditemmodel->setHeaderData(c, Qt::Horizontal, qsqlmodel->headerData(c, Qt::Horizontal));
for(int r=0; r<qsqlmodel->rowCount(); r++)
{
qstandarditemmodel->setData(qstandarditemmodel->index(r, c), qsqlmodel->record(r).value(c));
}
}

Thanks in advance

wysota
21st March 2008, 20:30
It might prove faster to subclass the sql model and add the functionality you need. What do you need the standard item model for?

sgmurphy19
22nd March 2008, 18:32
I need to be able to update the cells directly. Basically I can't have it read only. Yet I can't use the relationship model because the table relationships are too complex.

wysota
22nd March 2008, 18:47
Maybe you could just make a view in your database and use QSqlTableModel to operate on it?