11 March 2022
I'm having some issues working with a QSqlTableModel.
I'm reading/writing in a SQLite DB with a single table with just one field that accepts real numbers.
I've connected the model to a tableview and I can display and edit the rows present in the table.
I've then tried to implement two methods of the subclassed QSqlTableModel to add new empty records to the table and remove the selected one; here are their two implementations:
def new_record(self):
new_record = self.record()
new_record.setValue("point", 0)
self.insertRecord(self.rowCount(), new_record)
self.submitAll()
self.select()
def delete_record(self, index):
self.removeRow(index.row())
self.submitAll()
self.select()
In the delete method index is obtained as tableView.currentIndex() in the calling function.
The first method actually adds the new rows to the table and these are correctly displayed; but when I try to remove any of those newly create records with the second method all of them are deleted, not just the selected one.
Am I missing something really basic here? I looked around on SO and other sources but I couldn't find any solution to the matter.
Freyatext not yet in the index
Hello Florian, I wrote you a PM regarding the project, I am still looking for a dev.