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

Phil Thompson phil at riverbankcomputing.com
Fri Feb 12 11:14:43 GMT 2016


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.

Phil


More information about the PyQt mailing list