The Qt4.4 Doc, in the SQL section, has the following example for connecting an opened SQL form to a QTableView widget:
view->setModel(model);
view->show();
QTableView *view = new QTableView;
view->setModel(model);
view->show();
To copy to clipboard, switch view to plain text mode
However, when I try something similar:
model.setTable("employee");
model.setFilter("salary > 50000");
model.setSort(2, Qt::DescendingOrder);
model.select();
for (int i = 0; i < model.rowCount(); ++i) {
QString name
= model.
record(i
).
value("name").
toString();
int salary = model.record(i).value("salary").toInt();
qDebug() << name << salary;
}
model.insertRows(row, 1);
model.setData(model.index(row, 0), 1013);
model.setData(model.index(row, 1), "Peter Gordon");
model.setData(model.index(row, 2), 68500);
model.submitAll();
ui.cueTable->setModel(model);
QSqlTableModel model;
model.setTable("employee");
model.setFilter("salary > 50000");
model.setSort(2, Qt::DescendingOrder);
model.select();
for (int i = 0; i < model.rowCount(); ++i) {
QString name = model.record(i).value("name").toString();
int salary = model.record(i).value("salary").toInt();
qDebug() << name << salary;
}
model.insertRows(row, 1);
model.setData(model.index(row, 0), 1013);
model.setData(model.index(row, 1), "Peter Gordon");
model.setData(model.index(row, 2), 68500);
model.submitAll();
ui.cueTable->setModel(model);
To copy to clipboard, switch view to plain text mode
I get
"src/cues.cpp:38: error: no matching function for call to ‘QTableView::setModel(QSqlTableModel&)â€⠄¢
/usr/include/qt4/QtGui/qtableview.h:73: note: candidates are: virtual void QTableView::setModel(QAbstractItemModel*)
make: *** [build/cues.o] Error 1"
I cant tell why.. As far as I understood, QSqlTableModel Was a QAbstractItemModel. I'm trying to put the model into a QTableView, just like in the example, but it won't accept it.
Why is this?
Thank you
Bookmarks