[PyQt] Segfault when trying to rely on QStyledItemDelegate.setEditorData/ModelData default behavior

Elvis Stansvik elvstone at gmail.com
Fri Feb 12 12:34:46 GMT 2016


2016-02-12 13:31 GMT+01:00 Elvis Stansvik <elvstone at gmail.com>:
> 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..?

Or rather, crashes because a QVariant is being casted to a dict
somewhere I mean.

Elvis

>
> Elvis
>
>>
>> Phil


More information about the PyQt mailing list