[PyQt] QSqlTableModel edit problem

Jian Ma jianmarf at gmail.com
Mon Sep 19 17:07:56 BST 2011


I tried to add/edit records using QSqlTableModel and QTableView.  The
QSqlTableModel is initialized as: self.model = QSqlTableModel(self),
self.model.setTable(table), where table is a database,
self.model.setHeaderData(ID, ....).....; the QTableView is initialized as
self.view = QTableView(self), self.view.setModel(self.model). The addRecord
function is as:
row = self.model.rowCount()
index = self.model.index(row, 1)

The code doesn't work as expected. It shows that index was invalid. I found
that the self.model has 1 row and 0 column. I don't understand why the model
has 0 column. Can someone give any suggestions?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110919/196b034b/attachment.html>

More information about the PyQt mailing list