Change database data in the QTabelView
I have shown the data in a QTabelView through the following codes:
Code:
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);
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
to change the data through the QTableView, but I failed.
Who has the same problem and give me a hand??
Thank you in advance!!
Re: Change database data in the QTabelView
If You use OnManualSubmit you have to submitAll data.
Use a QPushButton and connect the clicked signal to a custom slot, that call's:
Code:
tableView->submitAll();
Re: Change database data in the QTabelView
I have to what you said, but it didn't work.
And even if I change the argument of
into it doesn't work either, where is wrong
Re: Change database data in the QTabelView
This is what I get from the console when I run the application:
Starting H:/QTprojects/testsqlite2/debug/testsqlite2.exe...
QSqlQuery::value: not positioned on a valid record
QSqlQuery::value: not positioned on a valid record
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
H:/QTprojects/testsqlite2/debug/testsqlite2.exe exited with code 0
Is there something wrong with my application??