PDA

View Full Version : How to update the selected row in QTableview using a button



lmofallis
3rd April 2017, 16:58
Hi,

I am using a QSqlTableModel for a SQlite database.
The SQLite database contains a:
- Table: "ThePer"
- Columns: ID, Name, Work.

Also, I have a Tableview to display the database's content, and a button to update the content of the selected row.
When I click the button to update the 'Work' column of the selected row, thats work only the first time. And doesn't work when I want to update an other selected row.


This is a short code of my 12422:


QModelIndex TheIndex = ui->tableView->selectionModel()->currentIndex();
TheModel->setEditStrategy(QSqlTableModel::OnFieldChange);
TheModel->setData(TheModel->index(TheIndex.row(),2), true, Qt::EditRole);
TheModel->select();
// TheModel->submitAll();
TheDB.close();


Thanks.