[PyQt] Segfault when activating items in a view
peter at lohmanders.se
peter at lohmanders.se
Mon Aug 9 08:09:32 BST 2010
Hello!
No matter how I implement my own item models, they segfault when ever they
are used with a view and an item is activated.
Example minimalistic model I test with:
import sys
from PyQt4 import QtGui, QtCore
class TestModel(QtCore.QAbstractTableModel):
def headerData(self, section, orientation, role =
QtCore.Qt.DisplayRole):
return QtCore.QVariant("a")
def data(self, index, role = QtCore.Qt.DisplayRole):
if role == QtCore.Qt.DisplayRole:
return QtCore.QVariant("t")
return QtCore.QVariant()
def columnCount(self, index):
return 2
def rowCount(self, index):
return 2
def onActivated():
print "activated"
if __name__ == "__main__":
app = QtGui.QApplication([])
win = QtGui.QMainWindow()
model = TestModel()
view = QtGui.QTreeView()
view.setModel(model)
app.connect(view, QtCore.SIGNAL("activated("")"),
onActivated)
view.setRootIsDecorated(False)
win.setCentralWidget(view)
win.show()
app.exec_()
To reproduce the segfault I set the model for a table or tree view and just
double click one of the 4 empty cells. If the item is editable the editor
appears and nothing happens. If the item is not editable and is activated
there's a delay of 0.5-1.0 seconds before a segfault pops up.
I get no warnings and no errors from PyQt or Python and I don't have the
debug versions available, but here's the bt from gdb anyway:
#0 0x00007ffff7abab7f in PyDict_GetItem () from
/usr/lib/libpython2.6.so.1.0
#1 0x00007ffff7aa9d10 in PyFrame_New () from /usr/lib/libpython2.6.so.1.0
#2 0x00007ffff7b16c97 in PyEval_EvalCodeEx () from
/usr/lib/libpython2.6.so.1.0
#3 0x00007ffff7aaa9cf in function_call () from /usr/lib/libpython2.6.so.1.0
#4 0x00007ffff7a83893 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#5 0x00007ffff7a9644f in instancemethod_call () from
/usr/lib/libpython2.6.so.1.0
#6 0x00007ffff7a83893 in PyObject_Call () from /usr/lib/libpython2.6.so.1.0
#7 0x00007ffff7b0fb43 in PyEval_CallObjectWithKeywords () from
/usr/lib/libpython2.6.so.1.0
#8 0x00007ffff425413b in ?? () from /usr/lib/python2.6/site-packages/sip.so
#9 0x00007ffff59bad94 in ?? () from
/usr/lib/python2.6/site-packages/PyQt4/QtCore.so
#10 0x00007ffff5a99460 in ?? () from
/usr/lib/python2.6/site-packages/PyQt4/QtCore.so
#11 0x00007ffff560a3bd in QAbstractTableModel::hasChildren(QModelIndex
const&) const () from /usr/lib/libQtCore.so.4
#12 0x00007ffff336d977 in ?? () from /usr/lib/libQtGui.so.4
Obviously, no matter how bad you write your models PyQt shouldn't segfault.
I use version 4.7.4-2 on a 64-bit Linux system (Archlinux), but it also
segfaults with 4.4.4-6 on a Debian system.
This is a new problem, I have many models in other applications that work
fine, I have no idea why this is happening, any help is appreciated.
/Peter
More information about the PyQt
mailing list