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

List:       pykde
Subject:    Re: [PyQt] Segfault with QString
From:       "=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=" <gruszczy () gmail ! com>
Date:       2008-03-21 18:09:03
Message-ID: 1be78d220803211109q7ca627abv111c79b50a8cd3cd () mail ! gmail ! com
[Download RAW message or body]

Copying would be much more intuitive in my opinion. Thanks for your
help, now I know a bit more, about what happens inside.

2008/3/21, Phil Thompson <phil@riverbankcomputing.com>:
> On Friday 21 March 2008, Filip GruszczyƄski wrote:
>
> > > This is the same issue that came up the other day in the context of
>  > > events. The QString that value is wrapping is a temporary, so you either
>  > > need to convert it (as you do when calling str()) or copy it (by calling
>  > > QString()).
>  >
>  > Could you explain it a bit further or send me to a proper
>  > documentation? I would like to understand it better, so I would really
>  > appreciate some clear explanation.
>
>
> When PyQt wraps a const reference to a QString it just saves the address of
>  that QString in the Python object. If the QString is then destroyed the
>  pointer becomes invalid and may segfault if it is subsequently dereferenced.
>  The solution is to copy the QString before it is destroyed.
>
>  A better solution might be for PyQt to automatically copy such things when
>  wrapping them. This would also avoid another problem where it is possible to
>  modify a const C++ instance from Python. I haven't yet convinced myself that
>  such a change will be safe (ie. won't break existing code).
>
>
>  Phil
>
>  _______________________________________________
>  PyQt mailing list    PyQt@riverbankcomputing.com
>  http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


-- 
Filip GruszczyƄski

_______________________________________________
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