[PyQt] QVariant bug(?)

Arve Knudsen arve.knudsen at gmail.com
Fri Sep 12 13:40:49 BST 2008


On Fri, Sep 12, 2008 at 1:41 PM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Wed, 10 Sep 2008 15:07:57 +0200, "Arve Knudsen" <arve.knudsen at gmail.com>
> wrote:
>> I'm getting a really mysterious segfault now, triggered by this
>> slightly modified case. Using the latest SIP/PyQt snapshots.
>>
>> Arve
>>
>> On Wed, Sep 3, 2008 at 1:43 PM, Arve Knudsen <arve.knudsen at gmail.com>
>> wrote:
>>> On Wed, Sep 3, 2008 at 10:13 AM, Phil Thompson
>>> <phil at riverbankcomputing.com> wrote:
>>>> On Wed, 3 Sep 2008 08:07:25 +0200, "Arve Knudsen"
>> <arve.knudsen at gmail.com>
>>>> wrote:
>>>>> On Tue, Sep 2, 2008 at 11:15 PM, Phil Thompson
>>>>> <phil at riverbankcomputing.com> wrote:
>>>>>> On Tue, 2 Sep 2008 22:12:54 +0200, "Arve Knudsen"
>>>>> <arve.knudsen at gmail.com>
>>>>>> wrote:
>>>>>>> On Tue, Sep 2, 2008 at 4:04 PM, Phil Thompson
>>>>>>> <phil at riverbankcomputing.com> wrote:
>>>>>>>> On Tue, 2 Sep 2008 11:29:00 +0200, "Arve Knudsen"
>>>>>>> <arve.knudsen at gmail.com>
>>>>>>>> wrote:
>>>>>>>>> I have created a simple test case which triggers a likely bug in
>>>>> PyQt.
>>>>>>>>> As the case demonstrates, I have a class template "PropertyValue"
>>>>>>>>> which I wrap and use with QVariant. When I run the test program
>>>>>>>>> ("tst.py") however, there is a segfault in the PropertyValue copy
>>>>>>>>> constructor. The reason as far as I've been able to tell is that
>> PyQt
>>>>>>>>> doesn't register its own metatype for "StringValue"
>>>>>>>>> (PropertyValue<QString>), since this is already constructed for
>> the
>>>>>>>>> C++ type (see qobject.sip, line 1479), with chaotic results (the
>> C++
>>>>>>>>> copy constructor receives a raw PyObject for the right-hand-side
>>>>>>>>> argument).
>>>>>>>>
>>>>>>>> The bug should be fixed in tonight's PyQt snapshot.
>>>>>>>>
>>>>>>>> However, it leaves the question as to how you would get the
>> instance
>>>>>>> back
>>>>>>>> out of the QVariant. QVariant.toPyObject() only handles Python
>> objects
>>>>>>> at
>>>>>>>> the moment - not wrapped non-Qt C++ instances as you have.
>>>>>>>>
>>>>>>>> I think I need to add an optional type argument to toPyObject(),
>> eg...
>>>>>>>>
>>>>>>>>    my_string_value = variant.toPyObject(StringValue)
>>>>>>>
>>>>>>> I don't understand what you mean here. QVariant.toPyObject currently
>>>>>>> works with StringValue objects?
>>>>>>
>>>>>> No, and it still won't after the bug is fixed - but there needs to be
>>>>> some
>>>>>> way to convert the C++ instance to a Python object (ie. to do the
>>>>> reverse
>>>>>> of what your test case does).
>>>>>
>>>>> Well, I'm confused, since I patched PyQt myself, and calling
>>>>> toPyObject() on the QVariant in my case returns the expected
>>>>> StringValue object.
>>>>
>>>> Obviously I can't comment on the behaviour of your patched version.
>>>
>>> All I did was mangle names of Python types, so they are distinct from
>>> C++ counterparts (add a PyQt-specific prefix).
>>>
>>> Arve
>
> Should be fixed by tonight's SIP snapshot.

Great.

Arve


More information about the PyQt mailing list