[PyQt] This program made python seg fault,how to solve?
Fei Xue
xuefey at gmail.com
Sat Oct 24 19:24:05 BST 2009
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.
When I use PyQt 4.4,the crash will not happen.Under PyQt 4.5/4.6,python
does crash.
# -*- coding: utf-8 -*-
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSql import *
import sys
def createConnection():
db=QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName("test0.db")
db.open()
def createTable():
q=QSqlQuery()
q.exec_("create table if not exists t1 (f1 integer primary key,f2
integer)")
q.exec_("delete from t1")
q.exec_("insert into t1 values(1,0)")
q.exec_("insert into t1 values(2,3)")
q.exec_("commit")
class Model(QSqlTableModel):
def __init__(self,parent=None):
QSqlTableModel.__init__(self,parent)
self.setTable("t1")
self.select()
self.setEditStrategy(QSqlTableModel.OnManualSubmit)
self.connect(self,SIGNAL("beforeUpdate(int,QSqlRecord&)"),
self.beforeUpdateTable)
def beforeUpdateTable(self,row,rec):
rec.setValue("f1",999)
class TestWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
vbox=QVBoxLayout(self)
t=QTableView()
m=Model()
t.setModel(m)
b=QPushButton("submit")
vbox.addWidget(t)
vbox.addWidget(b)
self.connect(b,SIGNAL("clicked()"),m.submitAll)
def main():
a=QApplication(sys.argv)
createConnection()
createTable()
w=TestWidget()
w.show()
sys.exit(a.exec_())
if __name__=="__main__":
main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091024/883f0a3b/attachment.html
More information about the PyQt
mailing list