[PyKDE] Segmentation fault with dynamic creating of widget content
Wido Depping
wido.depping at tu-clausthal.de
Tue Jun 17 22:56:00 BST 2003
On Tuesday 17 June 2003 14:39, Phil Thompson wrote:
> On Tuesday 17 June 2003 10:40 am, Wido Depping wrote:
> > On Tuesday 17 June 2003 10:26, Phil Thompson wrote:
> > > On Monday 16 June 2003 11:34 pm, Wido Depping wrote:
> > > > I have a widget whose children are created dynamicly. if i get new
> > > > data i have to refresh the widget, delete all it's children and
> > > > create the child-widgets again. Most of the time this method works,
> > > > but sometimes i get a segmentation fault.
> > > > This is the method for the deletion of the children:
> > > > for x in self.attributeWidget.children():
> > > > name = str(x.name())
> > > > # this ensures, that the layout is not deleted
> > > > # every label, lineedit and button has a name which starts with
> > > > 'LDAP' if name[:4] == "LDAP":
> > > > x.destroy()
> > > > self.attributeWidget.removeChild(x)
> > > >
> > > > So, is my code wrong or is it PyQt's fault? Attached is a backtracke
> > > > i got from gdb:
> > >
> > > What happens if you call removeChild() before you call destroy()?
> >
> > Then I get a segmentation fault, too. This time it happens, if I refresh
> > the widget and then press 'Alt'. It also happens if I minimize and
> > restore the window. Also with the same backtrace.
> > That's why I executed the destroy() before removeChild().
>
> You should definately do the removeChild() first. I would also "del x"
> rather than "x.destroy()". Other than that, have you got a small, but
> complete, example that demonstrates the problem.
Ok, I think I have a testcase, which should trigger the error. Needed some
time to find out, what was triggering the segfault.
I create for each row a button and install a eventfilter. After leaving the
eventfilter, the event is normally processed. And this might be the cause of
the error.
If you try to switch between the openend windows often and fast enough, the
errorr occurs with a similar backtracke I get with my real programm.
Attached is the sourcecode. Run with 'python TestWidget.py'
Wido
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestWidget.py
Type: text/x-python
Size: 955 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20030617/641b33a2/TestWidget.py
More information about the PyQt
mailing list