[PyKDE] PyQt and trees
Andreas Pakulat
apaku at gmx.de
Mon Apr 10 22:54:37 BST 2006
On 10.04.06 22:15:15, Bert Rodiers wrote:
> On 4/10/06, Bert Rodiers <bert.rodiers at gmail.com> wrote:
> > On 4/9/06, Andreas Pakulat <apaku at gmx.de> wrote:
> >
> > > Provide a minimal compilable example that demonstrates your problem. We
> > > can't tell what's going on from the snippet above, at least I can't.
> > >
> >
> > Ok, I'll do that (tomorrow). I'll have to reduce the amount of code.
>
> In attachment an example for the first problem (the rest will
> follow...). The tree should be filled in when I push the button. If I
> put a breakpoint in the __init__ of class TreeModel it works,
> otherwise it doesn't.
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.
Andreas
--
You'll wish that you had done some of the hard things when they were easier
to do.
More information about the PyQt
mailing list