On 11.04.06 11:59:10, Bert Rodiers wrote: > On 4/10/06, Andreas Pakulat <[EMAIL PROTECTED]> 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. > > 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.
On first sight I thought so too. And I believe I had some discussions with Phil about <someview>.setModel taking ownership of the model so there's at least one reference to the model, but I can't remember the "outcome". Anyway I guess this is because the normal treeview is only a wrapper around the c++-class and due to this doesn't store a python reference to the model that is set. Andreas -- You own a dog, but you can only feed a cat. _______________________________________________ PyKDE mailing list [email protected] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
