[PyKDE] PyQt and trees

Bert Rodiers bert.rodiers at gmail.com
Tue Apr 11 10:59:10 BST 2006


On 4/10/06, Andreas Pakulat <apaku at gmx.de> wrote:

> This one's easy: The model instance is local to the test function and
> thus gets garbage collected when test ends. So the Tree doesn't have a
> model to work with at that point. Changing test to
>
> def test(self):
>   self.model = TreeModel()
>   self.treeView.setModel(self.model)
>
> makes the app work. Or you could make the TreeModel a child of the
> treeView or some other QObject derived instance that you have. It's just
> important that at least 1 reference to the created object is available
> after the function is done so the object is not gc'ed.
>

Thank you Andreas,

I'm mainly a C++ programmer who recently started experimenting with
Python. I thought the object wouldn't go out of scope since the
self.treeView would keep a reference to it, but apparently I was
mistaken.

Thanks again,
Bert




More information about the PyQt mailing list