I have shown the data in a QTabelView through the following codes:
model->setTable("Person");
model->select();
model->removeColumn(0); // don't show the ID
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
model->setHeaderData(1, Qt::Horizontal, tr("Sex"));
model->setHeaderData(2, Qt::Horizontal, tr("Age"));
ui->tableView->setModel(model);
QSqlTableModel *model = new QSqlTableModel;
model->setTable("Person");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->removeColumn(0); // don't show the ID
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
model->setHeaderData(1, Qt::Horizontal, tr("Sex"));
model->setHeaderData(2, Qt::Horizontal, tr("Age"));
ui->tableView->setModel(model);
To copy to clipboard, switch view to plain text mode
But when I change the data in the tableview, the data in the table do not change. when I update the tableview, the data are the same as they were before changed.
How can I change the data in a QSLite table, through the QTabeView.
The help of Qt says that we can use
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
To copy to clipboard, switch view to plain text mode
to change the data through the QTableView, but I failed.
Who has the same problem and give me a hand??
Thank you in advance!!
Bookmarks