[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Segfault when trying to rely on QStyledItemDelegate.setEditorData/ModelData default behav
From: Elvis Stansvik <elvstone () gmail ! com>
Date: 2016-02-12 17:50:02
Message-ID: CAHms=eb+9d78FN2H8-1DAstZKdOMEbin-ZEcE13KjC+9jwqu6A () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Den 12 feb 2016 6:32 em skrev "Phil Thompson" <phil@riverbankcomputing.com>:
>
> On 12 Feb 2016, at 5:14 pm, Elvis Stansvik <elvstone@gmail.com> wrote:
> >
> > 2016-02-12 17:42 GMT+01:00 Phil Thompson <phil@riverbankcomputing.com>:
> >> On 12 Feb 2016, at 2:27 pm, Elvis Stansvik <elvstone@gmail.com> wrote:
> >>>
> >>> 2016-02-12 13:35 GMT+01:00 Phil Thompson <phil@riverbankcomputing.com
>:
> >>>> On 12 Feb 2016, at 12:31 pm, Elvis Stansvik <elvstone@gmail.com>
wrote:
> >>>>>
> >>>>> 2016-02-12 12:14 GMT+01:00 Phil Thompson <
phil@riverbankcomputing.com>:
> >>>>>> On 11 Feb 2016, at 8:53 pm, Elvis Stansvik <elvstone@gmail.com>
wrote:
> >>>>>>>
> >>>>>>> 2016-02-11 21:14 GMT+01:00 Elvis Stansvik <elvstone@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.
> >
> > Excellent! :) Since we're basing our product on Debian packaged PyQt,
> > I'll just live with having the "transport" QVariant property for now.
> >
> > Just out of curiosity, was this a fix of some general problem so to
> > speak, or was the fix to add some custom code (to the wrapping of
> > QStyledItemDelegate::setEditorData) that handles this particular case?
>
> It was a general problem.
Alright, even better that it got fixed then.
Elvis
>
> Phil
[Attachment #5 (text/html)]
<p dir="ltr">Den 12 feb 2016 6:32 em skrev "Phil Thompson" <<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>>:<br> ><br>
> On 12 Feb 2016, at 5:14 pm, Elvis Stansvik <<a \
href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>> wrote:<br> > ><br>
> > 2016-02-12 17:42 GMT+01:00 Phil Thompson <<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>>:<br> > \
>> On 12 Feb 2016, at 2:27 pm, Elvis Stansvik <<a \
href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>> wrote:<br> > >>><br>
> >>> 2016-02-12 13:35 GMT+01:00 Phil Thompson <<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>>:<br> > \
>>>> On 12 Feb 2016, at 12:31 pm, Elvis Stansvik <<a \
href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>> wrote:<br> > \
>>>>><br> > >>>>> 2016-02-12 12:14 GMT+01:00 Phil Thompson \
<<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>>:<br> > \
>>>>>> On 11 Feb 2016, at 8:53 pm, Elvis Stansvik <<a \
href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>> wrote:<br> > \
>>>>>>><br> > >>>>>>> 2016-02-11 21:14 GMT+01:00 \
Elvis Stansvik <<a href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>>:<br> > \
>>>>>>>> I found the problem, I had forgot to change the user property \
from<br> > >>>>>>>> dict to QVariant (was testing around).<br>
> >>>>>>>><br>
> >>>>>>>> With the property of type QVariant, it seems to work \
fine.<br> > >>>>>>><br>
> >>>>>>> I'm actually still interested in why I need to declare \
the Qt property<br> > >>>>>>> as QVariant here. Why do I get a segfault \
if I declare it as dict?<br> > >>>>>>><br>
> >>>>>>> That is, in the paste<br>
> >>>>>>> <a \
href="https://gist.github.com/estan/c051d1f798c4c46caa7d">https://gist.github.com/estan/c051d1f798c4c46caa7d</a> \
, why must it be<br> > >>>>>>><br>
> >>>>>>> @pyqtProperty(QVariant, user=True)<br>
> >>>>>>> def values(self):<br>
> >>>>>>> return self._values<br>
> >>>>>>><br>
> >>>>>>> and not<br>
> >>>>>>><br>
> >>>>>>> @pyqtProperty(dict, user=True)<br>
> >>>>>>> def values(self):<br>
> >>>>>>> return self._values<br>
> >>>>>>><br>
> >>>>>>> ?<br>
> >>>>>>><br>
> >>>>>>> The value I store there (self._values) is a dict after all. \
Does it<br> > >>>>>>> have something to do with the way in which<br>
> >>>>>>> QStyledItemDelegate::setEditorData sets the property?<br>
> >>>>>><br>
> >>>>>> Yes. It passes the address of a QVariant. PyQt uses the type of \
the property to tell it what to do with the address.<br> > >>>>><br>
> >>>>> Aha, I think I understand: QStyledItemDelegate::setEditorData \
wraps<br> > >>>>> the value in a QVariant, and then crashes when trying to \
set the<br> > >>>>> property, because QVariant can't be converted to \
dict..?<br> > >>>><br>
> >>>> 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.<br> > \
>>><br> > >>> Hm, okay. But my goal was to keep this property as a dict, \
since<br> > >>> that's the data I'm storing, and not a QVariant. Why \
can't I declare<br> > >>> the property as a dict (since that's the data the \
editor is working<br> > >>> with), and then when QStyledItemDelegate::setEditorData \
sets the<br> > >>> property with a QVariant (which contains my dict), that QVariant \
is<br> > >>> automatically converted to a dict? (since that's what the property \
is<br> > >>> declared as).<br>
> >>><br>
> >>> Sorry if I'm a little thick :/<br>
> >><br>
> >> No, I am.<br>
> >><br>
> >> Should be fixed in tonight's snapshot.<br>
> ><br>
> > Excellent! :) Since we're basing our product on Debian packaged PyQt,<br>
> > I'll just live with having the "transport" QVariant property for \
now.<br> > ><br>
> > Just out of curiosity, was this a fix of some general problem so to<br>
> > speak, or was the fix to add some custom code (to the wrapping of<br>
> > QStyledItemDelegate::setEditorData) that handles this particular case?<br>
><br>
> It was a general problem.</p>
<p dir="ltr">Alright, even better that it got fixed then.</p>
<p dir="ltr">Elvis</p>
<p dir="ltr">><br>
> Phil</p>
[Attachment #6 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic