[PyQt] References returned from C++
phil at riverbankcomputing.com
Sun Jun 22 14:53:34 BST 2008
On Sun, 22 Jun 2008 14:26:20 +0200, Detlev Offenbach
<detlev at die-offenbachs.de> wrote:
> On Sonntag, 22. Juni 2008, Phil Thompson wrote:
>> On Sun, 22 Jun 2008 12:53:41 +0200, "Arve Knudsen"
> <arve.knudsen at gmail.com>
>> > How does one normally treat references returned by SIP-wrapped C++
>> > objects? I just determined a segmentation fault in my program resulted
>> > from an object first being obtained as a reference (in the C++ sense)
>> > from a C++ method, and then destroyed with the parent object. Does one
>> > normally keep in mind that the object dies implicitly with its C++
>> > parent, or is there a way to have SIP give you copies rather than
>> > borrowed references?
>> I will probably change SIP to make a copy when the reference is const. I
>> think this fixes most of the problem areas although it does introduce an
>> For example...
>> const Status &status = foo->status();
>> while (!status.finished)
>> ...with the planned change a directly translated Python version would no
>> longer work. Instead you would have to move the call to status() to be
>> inside the loop...
>> while not foo.status().finished:
> But that change could seriously harm applications written using PyQt like
> eric4. I would have to scan through all the code, which could stop
> development for several weeks (or even months). Please don't do that!!!!!
I think you've misunderstood.
>> While I don't think there is anything in PyQt that would be affected by
>> this, SIP is used for much more than just PyQt.
It's only a problem if a const reference to an instance of a wrapped class
is returned and that instance is subsequently updated by the C++ code. As I
said, I don't think there is such a wrapped class in PyQt.
More information about the PyQt