[PyKDE] Segmentation fault with dynamic creating of widget content

Phil Thompson phil at riverbankcomputing.co.uk
Tue Jun 17 14:40:01 BST 2003


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.

Phil




More information about the PyQt mailing list