Hi! The code below can make python seg fault. Steps to reproduce: run this program,modify the value of a cell, then click submit button,python will seg fault.The correct result is the value of the second column will change to 999 after click submit buttoon.<br>
<br>When I use PyQt 4.4,the crash will not happen.Under PyQt 4.5/4.6,python does crash. <br># -*- coding: utf-8 -*-<br>from PyQt4.QtGui import *<br>from PyQt4.QtCore import *<br>from PyQt4.QtSql import *<br>import sys<br>
def createConnection():<br> db=QSqlDatabase.addDatabase("QSQLITE")<br> db.setDatabaseName("test0.db")<br> db.open()<br> <br>def createTable():<br> q=QSqlQuery()<br> q.exec_("create table if not exists t1 (f1 integer primary key,f2 integer)")<br>
q.exec_("delete from t1")<br> q.exec_("insert into t1 values(1,0)")<br> q.exec_("insert into t1 values(2,3)")<br> q.exec_("commit")<br><br> <br>class Model(QSqlTableModel):<br>
def __init__(self,parent=None):<br> QSqlTableModel.__init__(self,parent)<br> self.setTable("t1")<br> self.select()<br> self.setEditStrategy(QSqlTableModel.OnManualSubmit)<br> self.connect(self,SIGNAL("beforeUpdate(int,QSqlRecord&)"),<br>
self.beforeUpdateTable)<br> def beforeUpdateTable(self,row,rec):<br> rec.setValue("f1",999)<br>class TestWidget(QWidget):<br> def __init__(self):<br> QWidget.__init__(self)<br>
vbox=QVBoxLayout(self)<br> t=QTableView()<br> m=Model()<br> t.setModel(m)<br> b=QPushButton("submit")<br> vbox.addWidget(t)<br> vbox.addWidget(b)<br> self.connect(b,SIGNAL("clicked()"),m.submitAll)<br>
def main():<br> a=QApplication(sys.argv)<br> createConnection()<br> createTable()<br> w=TestWidget()<br> w.show()<br> sys.exit(a.exec_())<br>if __name__=="__main__":<br> main()<br> <br>