[PyKDE] The strangest problem I've ever seen
Jim Bublitz
jbublitz at nwinternet.com
Tue Jul 2 01:36:00 BST 2002
On 01-Jul-02 Willi Richert wrote:
> Hi,
> look at the following code which returns segfault when it exits.
>
>####################################################
> from qt import *
> import sys
>
> class MyWindow(QMainWindow):
> def __init__(self):
> QMainWindow.__init__(self)
>
> self.Toolbar = QToolBar("",self,Qt.DockTop)
>
>
> def main(args):
> a=QApplication(args)
> w=MyWindow()
> w.show()
> QObject.connect(a, SIGNAL("lastWindowClosed()"), a,
> SLOT("quit()"))
> a.exec_loop()
>
> if __name__ == "__main__":
> main(sys.argv)
>####################################################
> Now replace the variable "a" by any other name and it does
> segfault any more.
It segfaults with 'a' or 'b' for the variable name
for me, but only at exit.
> Does anybody know, why?
> Also, if I delete the toolbar line it works with "a" as the
> variable.
QMainWindow keeps a QList of toolbars (called 'toolbars').
It expects that you'll add toolbars using ... addToolbar(),
not by adding a child widget. I suspect if you look at
the QToolbar code, it has similar expectations and the
destructor code is getting confused about who owns the
QToolbar when the program exits. Try using addToolbar()
instead (see the Qt docs for QMainWindow).
Can't say why your seeing strange things with the variable
name, since I can't reproduce that.
Jim
More information about the PyQt
mailing list