Skip to content Skip to sidebar Skip to footer

Pyqt4 Qsqltablemodel, Qtableview Intermittent Update

I have a very strange bug that I can't seem to diagnose. I have a PyQt4 application that uses a QSqlTableModel to display data in a QTableView. I have repeated the bug in an iso

Solution 1:

Possible Explaination: Few more things that I have figured out. I think my basic problem is that my table does not define a primary key. When I create the table with a PRIMARY KEY instead of UNIQUE KEY, the problem goes away.

As far as PyQt4 goes, I have also learned that I need to hide columns (such as ID column) by using the QTableView's setColumnHidden method and not the QSqlTableModel's removeColumn. Once the ID column (primary key) is removed, then the updates get screwy.

I've also determined that if I'm using a view (granted that view has to be editable as required by MySQL), that I have to manually set the primary key in the QSqlTableModel. For example:

pk = QtSql.QSqlIndex("cursName","idxName")
pk.append(QtSql.QSqlField("ID"))
self.setPrimaryKey(pk)

Post a Comment for "Pyqt4 Qsqltablemodel, Qtableview Intermittent Update"