[PyKDE] PyQT Segfault on widget removal.

Henry Kleynhans henry at obsidian.co.za
Wed Jun 18 13:00:01 BST 2003


Hi Vio,

Thanks for the reply.

Would you use deleteLater() instead of removeChild() ?

The problem is that it works if the button is not inside another widget
which gets removed.  If you have the button on the QMainWindow instead of
the TestWidget, it works fine, but as soon as you put in into another
widget it does not work.
Kind regards,

Henry

On Wednesday 18 June 2003 09:40, Vio wrote:
> > I remember similar problems usind "delete()" or "destroy()" some time
> > ago  - sorry, I forgot the exact method name.
> > My simple workaround was to use "deleteLater()". Especially since
> > "Later" appears to be calcutated in milliseconds: pretty fast.
> >
> > Hope this helps,
> > Vio
> >
> > PS. Appologies if this information is redundant. I didn't follow this
> > thread from start.
> >
> > Henry Kleynhans wrote:
> > >Hi All,
> > >
> > >Given the recent segfault discussion, I have attached an example piece
> > > of code which segfaults.  I am not sure if this is a bug, or just my
> > > own stupidity though.  According to the PyQT book, the way to remove a
> > > widget from it's parent is to do the following:
> > >
> > >	myParent.removeChild(myChild)
> > >	del myChild
> > >
> > >The PyQT/Sip bindings seems to break if these commands gets triggered by
> > > a signal from within a child widget of the widget that is to be
> > > removed.
> > >
> > >I get a segfault when I do the following:
> > >
> > >	1.  Run the program (testdel.py)
> > >	2.  Click on the DelButton button.
> > >	3.  Switch to another application using Alt-Tab
> > >	4.  Switch back to my testdel app.
> > >
> > >This happens under RH9.0. (Python-2.2.2-26, PyQt-3.5-5, qt-3.1.1-6)  I
> > > use the KDE desktop environment.
> > >
> > >Does anyone know if this is a bug or how to fix/workaround this?
> > >
> > >TIA,
> > >
> > >Kind regards,
> > >
> > >Henry
> > >
> > >
> > >
> > >------------------------------------------------------------------------
> > >
> > >#!/usr/bin/python
> > >#
> > >#
> > >
> > >import sys
> > >from qt import *
> > >
> > >class TestWidget(QWidget):
> > >    def __init__(self, *args):
> > >
> > >        apply(QWidget.__init__, (self,) + args)
> > >
> > >        self.button     = QPushButton("DelButton", self)
> > >        self.button.resize(self.button.sizeHint())
> > >        QObject.connect(self.button, SIGNAL("clicked()"),
> > >                        self.slotClicked)
> > >
> > >        pass
> > >
> > >    def slotClicked(self):
> > >        self.emit(PYSIGNAL("sigKillButton"), ())
> > >        pass
> > >
> > >class MainWindow(QMainWindow):
> > >
> > >    def __init__(self, *args):
> > >
> > >        apply(QMainWindow.__init__, (self,) + args)
> > >
> > >        self.widget     = TestWidget(self)
> > >        self.connect(self.widget, PYSIGNAL("sigKillButton"),
> > >                     self.removeButton)
> > >        pass
> > >
> > >    def removeButton(self):
> > >        self.removeChild(self.widget)
> > >        del self.widget
> > >
> > >        self.addButton  = QPushButton("Added Button", self)
> > >        self.addButton.resize(self.addButton.sizeHint())
> > >        self.addButton.show()
> > >        pass
> > >
> > >    pass # MainWindow
> > >
> > >def main(args):
> > >    app = QApplication(args)
> > >    win = MainWindow()
> > >    win.show()
> > >    app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
> > >    app.exec_loop()
> > >    pass
> > >
> > >if __name__ == "__main__":
> > >    main(sys.argv)
> > >    pass
> >
> > _______________________________________________
> > PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> > http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

-- 
Henry Kleynhans <henry at obsidian.co.za>
Obsidian Systems




More information about the PyQt mailing list