[PyQt] QMainWindow bug?
antonio.valentino at tiscali.it
Wed Jan 19 10:27:06 GMT 2011
Il giorno Wed, 19 Jan 2011 09:46:19 +0000
Vicent Mas <uvemas at gmail.com> ha scritto:
> 2011/1/19 Antonio Valentino <antonio.valentino at tiscali.it>:
> > Hi Vicent,
> > Il giorno Tue, 18 Jan 2011 19:32:57 +0000
> > Vicent Mas <uvemas at gmail.com> ha scritto:
> >> Hi,
> >> it seems there is a bug in QMainWindow.createPopupMenu. In my
> >> system (Windows XP, Python 2.6, PyQt 4.8.2 installed using the
> >> Windows installer), when I run the attached script and close the
> >> created QMainWindow, an error dialog appears saying that
> >> python.exe has found a problem and must be closed.
> >> Could someone confirm this behavior? Thanks.
> > Segmentation fault on:
> > GNU/Linux x86_64 2.6.35 (Ubuntu 10.10)
> > Python 2.6.6
> > PyQt4 4.7.4
> > Qt4 4.7.0
> > No problem if I add
> > del toolbars_submenu
> > at the very and of the program
> > It seems that having around references to objects that are child of
> > the mainwin triggers the problem.
> > ciao
> > --
> > Antonio Valentino
> Antonio, your workaround works here. Thanks a lot. Anyway I think the
> current behavior is buggy. Even if I set the WA_DeleteOnClose flag on
> the main window (which I expected to delete the main window and its
> children when the window is closed) the script crashes if I don't
> apply your workaround.
I agree that the behavior is buggy (or at least unexpected).
If my understanding is correct the problem here is that python tries to
delete toolbars_submenu and file_toolbar objects *after* deletion of
main_window that, in turn, deletes all its children.
So when python deletes toolbars_submenu and file_toolbar the
underlying C++ object have already been deleted by the main_window
destructor and hence the segfault.
Adding WA_DeleteOnClose doesn't change this.
If I remember well (I'm not sure) the order in which python deletes
objects that go out of the scope is not specified, so there are
situations in which the bug is not triggered.
If you add the following lines at the end of the script (the original
you should be sure the bug, if any, is triggered.
If hypotheses are correct even Nick should get a segfaut now.
More information about the PyQt