Updating SQL Database from QTableView
I am trying to update an SQL Database from a QTableView. I can view the contents of my database in my QTableView as well as insert a row into the QTableView and have it appear in my Database via manual submit and clicking a button. However I have not been able to edit a cell in my QTableView and have the change appear in the Database. Can someone point me in the right direction?
Re: Updating SQL Database from QTableView
I still haven't been able to figure this out. I've been looking at the Cache Table example as a go by and what I'm trying to do isn't any different than what's in the example.
Re: Updating SQL Database from QTableView
Sounds like it could be your edit strategy setting.
I have a model/view set on a sqlite database table with
model->setEditStrategy(QSqlTableModel::OnFieldChange);
If I double click in a view cell, make an edit, then hit return, the data change is saved to the database table.
Re: Updating SQL Database from QTableView
I just noticed something when trying what you suggested, when a cell is already populated and I make a change then it works. When a cell is blank from adding a row and not setting the data yet it doesn't work. So I'll play with it some more. I'm guessing by adding a row with blank cells and not setting the data the TableView doesn't know how to handle the edit.
Re: Updating SQL Database from QTableView
I figured it out. When adding rows (at least from my tests) you have to set data for all fields even if you initially want them blank to fill in later.
Re: Updating SQL Database from QTableView
Great - glad you got it working. I never had the problem since my rows are always populated when created.