[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Ownership disconnect with "temporary" python objects?
From: Johan_Fläckman <flackman.johan () gmail ! com>
Date: 2015-04-16 8:18:14
Message-ID: CANpkKNcm=pQZe_9qXaLOvEBs7S11JAus+mkcCqb8q+2DbHinNQ () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Thanks for the quick reply.
I understand that I can work around it by making sure the instance does not
die within the addMenu-scope.
I kind of would have expected the QAction to pick up on the fact that its
C++ counterpart is destroyed though (and not crash).
Any idea why this is not a problem with python3?
On Thu, Apr 16, 2015 at 9:49 AM, Phil Thompson <phil@riverbankcomputing.com>
wrote:
> 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
[Attachment #5 (text/html)]
<div dir="ltr">Thanks for the quick reply.<div>I understand that I can work around it \
by making sure the instance does not die within the addMenu-scope.</div><div>I kind \
of would have expected the QAction to pick up on the fact that its C++ counterpart is \
destroyed though (and not crash).</div><div><br></div><div>Any idea why this is not a \
problem with python3?<br></div><div><br></div></div><div class="gmail_extra"><br><div \
class="gmail_quote">On Thu, Apr 16, 2015 at 9:49 AM, Phil Thompson <span \
dir="ltr"><<a href="mailto:phil@riverbankcomputing.com" \
target="_blank">phil@riverbankcomputing.com</a>></span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><span class="">On 16/04/2015 8:32 am, Johan Fläckman \
wrote:<br> </span><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""> Hi, I have a \
strange crash in PyQt5 and I'm not sure if the error is in my<br> buildscripts or \
in PyQt.<br> I have built Qt5, PyQt5 and SIP myself with msvc2010 / python 2.7<br>
<br>
PyQt 5.4.1<br>
Qt 5.4.1<br>
SIP 4.16.7<br>
<br>
My compiled version seems to work fine in almost all cases but I have this<br>
one crash that shows something went wrong.<br>
Here's a minimal script that reproduce the crash (imports etc omitted):<br>
<br></span>
*a = PyQt5.QtWidgets.QApplication(<u></u>sys.argv)*<br>
*w = PyQt5.QtWidgets.QMainWindow();<u></u>*<br>
<br>
*res = w.menuBar().addMenu( PyQt5.QtWidgets.QMenu( "foo" ) )*<br>
<br>
*print **res** # <---- PyQt5.QtWidgets.QAction \
object<br> at 0x000000000279E3A8*<br>
*sip.isdestroyed(res) # <---- False*<br>
*sip.ispyowned(res) # <----- False*<br>
*sip.dump(res) # <----- Crash (res already destroyed in \
C++)*<span class=""><br> <br>
<br>
From what I can tell from debugging:<br>
The QMenu instance passed to addMenu is deconstructed (both in python and<br>
in C++) before res is assigned in python.<br>
The menu's QAction is destroyed in C++ during (or right after) the<br>
deconstruction of the QMenu but res is assigned a python instance of a<br>
QAction that thinks this C++ representation still exists.<br>
<br></span>
I can *not *reproduce this crash with the prebuilt python 3.4 and the<br>
riverbank-pyqt5 binaries but I *can *reproduce it with any prebuilt<span \
class=""><br> "unofficial" pyqt5/python27 binaries I could find scattered \
around the<br> internet. The crash is reproducible in both debug and non-debug \
builds.<br> <br>
Has anyone else encountered this or can confirm that their python27/pyqt5<br>
version can run this code?<br>
</span></blockquote>
<br>
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.<br> <br>
Phil<br>
______________________________<u></u>_________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" \
target="_blank">PyQt@riverbankcomputing.com</a><br> <a \
href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" \
target="_blank">http://www.riverbankcomputing.<u></u>com/mailman/listinfo/pyqt</a></blockquote></div><br></div>
[Attachment #6 (text/plain)]
_______________________________________________
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