[PyQt] Segfault when trying to rely on QStyledItemDelegate.setEditorData/ModelData default behavior
Phil Thompson
phil at riverbankcomputing.com
Fri Feb 12 16:42:55 GMT 2016
On 12 Feb 2016, at 2:27 pm, Elvis Stansvik <elvstone at gmail.com> wrote:
>
> 2016-02-12 13:35 GMT+01:00 Phil Thompson <phil at riverbankcomputing.com>:
>> On 12 Feb 2016, at 12:31 pm, Elvis Stansvik <elvstone at gmail.com> wrote:
>>>
>>> 2016-02-12 12:14 GMT+01:00 Phil Thompson <phil at riverbankcomputing.com>:
>>>> On 11 Feb 2016, at 8:53 pm, Elvis Stansvik <elvstone at gmail.com> wrote:
>>>>>
>>>>> 2016-02-11 21:14 GMT+01:00 Elvis Stansvik <elvstone at gmail.com>:
>>>>>> I found the problem, I had forgot to change the user property from
>>>>>> dict to QVariant (was testing around).
>>>>>>
>>>>>> With the property of type QVariant, it seems to work fine.
>>>>>
>>>>> I'm actually still interested in why I need to declare the Qt property
>>>>> as QVariant here. Why do I get a segfault if I declare it as dict?
>>>>>
>>>>> That is, in the paste
>>>>> https://gist.github.com/estan/c051d1f798c4c46caa7d , why must it be
>>>>>
>>>>> @pyqtProperty(QVariant, user=True)
>>>>> def values(self):
>>>>> return self._values
>>>>>
>>>>> and not
>>>>>
>>>>> @pyqtProperty(dict, user=True)
>>>>> def values(self):
>>>>> return self._values
>>>>>
>>>>> ?
>>>>>
>>>>> The value I store there (self._values) is a dict after all. Does it
>>>>> have something to do with the way in which
>>>>> QStyledItemDelegate::setEditorData sets the property?
>>>>
>>>> Yes. It passes the address of a QVariant. PyQt uses the type of the property to tell it what to do with the address.
>>>
>>> Aha, I think I understand: QStyledItemDelegate::setEditorData wraps
>>> the value in a QVariant, and then crashes when trying to set the
>>> property, because QVariant can't be converted to dict..?
>>
>> A QVariant can be converted to a dict (otherwise your code wouldn't work at all) - but PyQt needs to know that it is a QVariant in the first place.
>
> Hm, okay. But my goal was to keep this property as a dict, since
> that's the data I'm storing, and not a QVariant. Why can't I declare
> the property as a dict (since that's the data the editor is working
> with), and then when QStyledItemDelegate::setEditorData sets the
> property with a QVariant (which contains my dict), that QVariant is
> automatically converted to a dict? (since that's what the property is
> declared as).
>
> Sorry if I'm a little thick :/
No, I am.
Should be fixed in tonight's snapshot.
Thanks,
Phil
More information about the PyQt
mailing list