[PyQt] segmentation fault
David Boddie
david at boddie.org.uk
Sat Oct 20 02:19:35 BST 2007
On Friday 19 October 2007 08:12:54 +0200, lucaberto wrote:
> > > ? ? def file_information(self):
> > > ? ? ? ? val = self.treeWidget.currentItem()
> > > ? ? ? ? indice = self.treeWidget.indexFromItem(val, 0)
> > >
> > > in this instruction :
> > >
> > > indice = self.treeWidget.indexFromItem(val, 0)
> >
> > Can you tell us what "val" contains? Is it "None"?
>
> The value of val is:<PyQt4.QtGui.QTreeWidgetItem object at 0x2abf1e34ee20>
That's strange, but I think I can see what the problem is.
Looking back at your previous message, you write this:
class Form(QWidget, Ui_Form):
"""
Class documentation goes here.
"""
def __init__(self, parent = None):
"""
Constructor
"""
QWidget.__init__(self, parent)
self.setupUi(self)
self.modello = QtGui.QDirModel()
self.treeWidget.setModel(self.modello)
Is self.treeWidget an instance of QTreeWidget? I'm assuming it is because
you later write
def file_information(self):
val = self.treeWidget.currentItem()
indice = self.treeWidget.indexFromItem(val, 0)
The problem is that you set a new model on a QTreeWidget instance, and it's
not designed to be used that way. QTreeWidget provides a nice, convenient,
item-based class that can be used to create trees of items. Internally, it
has its own model, and it's a subclass of QTreeView so it provides the
setModel() method, but you're not really supposed to give it a new model
to work with - it just doesn't expect it.
You should really use QTreeView with QDirModel, though I appreciate that
you may miss the item-based API that QTreeWidget provides.
David
More information about the PyQt
mailing list