[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] =?utf-8?q?Ownership_disconnect_with_=22temporary=22_python?=
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2015-04-16 7:49:17
Message-ID: cd17c73861f19e4bf36d812d3b61787b () riverbankcomputing ! com
[Download RAW message or body]

On 16/04/2015 8:32 am, Johan Fläckman wrote:
> Hi, I have a strange crash in PyQt5 and I'm not sure if the error is in 
> my
> buildscripts or in PyQt.
> I have built Qt5, PyQt5 and SIP myself with msvc2010 / python 2.7
> 
> PyQt 5.4.1
> Qt 5.4.1
> SIP 4.16.7
> 
> My compiled version seems to work fine in almost all cases but I have 
> this
> one crash that shows something went wrong.
> Here's a minimal script that reproduce the crash (imports etc omitted):
> 
> *a = PyQt5.QtWidgets.QApplication(sys.argv)*
> *w = PyQt5.QtWidgets.QMainWindow();*
> 
> *res = w.menuBar().addMenu( PyQt5.QtWidgets.QMenu( "foo" ) )*
> 
> *print **res**                     # <---- PyQt5.QtWidgets.QAction 
> object
> at 0x000000000279E3A8*
> *sip.isdestroyed(res)    # <---- False*
> *sip.ispyowned(res)     # <----- False*
> *sip.dump(res)            # <----- Crash (res already destroyed in 
> C++)*
> 
> 
> From what I can tell from debugging:
> The QMenu instance passed to addMenu is deconstructed (both in python 
> and
> in C++) before res is assigned in python.
> The menu's QAction is destroyed in C++ during (or right after) the
> deconstruction of the QMenu but res is assigned a python instance of a
> QAction that thinks this C++ representation still exists.
> 
> I can *not *reproduce this crash with the prebuilt python 3.4 and the
> riverbank-pyqt5 binaries but I *can *reproduce it with any prebuilt
> "unofficial" pyqt5/python27 binaries I could find scattered around the
> internet. The crash is reproducible in both debug and non-debug builds.
> 
> Has anyone else encountered this or can confirm that their 
> python27/pyqt5
> version can run this code?

It's a bug in your code. QMenuBar.addMenu(QMenu) does not take ownership 
of the menu. Give the menu a parent or keep an explicit reference to it.

Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic