[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 &quot;Phil Thompson&quot; &lt;<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>&gt;:<br> &gt;<br>
&gt; On 12 Feb 2016, at 5:14 pm, Elvis Stansvik &lt;<a \
href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>&gt; wrote:<br> &gt; &gt;<br>
&gt; &gt; 2016-02-12 17:42 GMT+01:00 Phil Thompson &lt;<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>&gt;:<br> &gt; \
&gt;&gt; On 12 Feb 2016, at 2:27 pm, Elvis Stansvik &lt;<a \
href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>&gt; wrote:<br> &gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; 2016-02-12 13:35 GMT+01:00 Phil Thompson &lt;<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>&gt;:<br> &gt; \
&gt;&gt;&gt;&gt; On 12 Feb 2016, at 12:31 pm, Elvis Stansvik &lt;<a \
href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>&gt; wrote:<br> &gt; \
&gt;&gt;&gt;&gt;&gt;<br> &gt; &gt;&gt;&gt;&gt;&gt; 2016-02-12 12:14 GMT+01:00 Phil Thompson \
&lt;<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>&gt;:<br> &gt; \
&gt;&gt;&gt;&gt;&gt;&gt; On 11 Feb 2016, at 8:53 pm, Elvis Stansvik &lt;<a \
href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>&gt; wrote:<br> &gt; \
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br> &gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; 2016-02-11 21:14 GMT+01:00 \
Elvis Stansvik &lt;<a href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>&gt;:<br> &gt; \
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I found the problem, I had forgot to change the user property \
from<br> &gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dict to QVariant (was testing around).<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; With the property of type QVariant, it seems to work \
fine.<br> &gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; I&#39;m actually still interested in why I need to declare \
the Qt property<br> &gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; as QVariant here. Why do I get a segfault \
if I declare it as dict?<br> &gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; That is, in the paste<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; <a \
href="https://gist.github.com/estan/c051d1f798c4c46caa7d">https://gist.github.com/estan/c051d1f798c4c46caa7d</a> \
, why must it be<br> &gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; @pyqtProperty(QVariant, user=True)<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; def values(self):<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;        return self._values<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; and not<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; @pyqtProperty(dict, user=True)<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; def values(self):<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;        return self._values<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; ?<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; The value I store there (self._values) is a dict after all. \
Does it<br> &gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; have something to do with the way in which<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;&gt; QStyledItemDelegate::setEditorData sets the property?<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt;&gt; 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> &gt; &gt;&gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;&gt; Aha, I think I understand: QStyledItemDelegate::setEditorData \
wraps<br> &gt; &gt;&gt;&gt;&gt;&gt; the value in a QVariant, and then crashes when trying to \
set the<br> &gt; &gt;&gt;&gt;&gt;&gt; property, because QVariant can&#39;t be converted to \
dict..?<br> &gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; A QVariant can be converted to a dict (otherwise your code wouldn&#39;t \
work at all) - but PyQt needs to know that it is a QVariant in the first place.<br> &gt; \
&gt;&gt;&gt;<br> &gt; &gt;&gt;&gt; Hm, okay. But my goal was to keep this property as a dict, \
since<br> &gt; &gt;&gt;&gt; that&#39;s the data I&#39;m storing, and not a QVariant. Why \
can&#39;t I declare<br> &gt; &gt;&gt;&gt; the property as a dict (since that&#39;s the data the \
editor is working<br> &gt; &gt;&gt;&gt; with), and then when QStyledItemDelegate::setEditorData \
sets the<br> &gt; &gt;&gt;&gt; property with a QVariant (which contains my dict), that QVariant \
is<br> &gt; &gt;&gt;&gt; automatically converted to a dict? (since that&#39;s what the property \
is<br> &gt; &gt;&gt;&gt; declared as).<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; Sorry if I&#39;m a little thick :/<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; No, I am.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Should be fixed in tonight&#39;s snapshot.<br>
&gt; &gt;<br>
&gt; &gt; Excellent! :) Since we&#39;re basing our product on Debian packaged PyQt,<br>
&gt; &gt; I&#39;ll just live with having the &quot;transport&quot; QVariant property for \
now.<br> &gt; &gt;<br>
&gt; &gt; Just out of curiosity, was this a fix of some general problem so to<br>
&gt; &gt; speak, or was the fix to add some custom code (to the wrapping of<br>
&gt; &gt; QStyledItemDelegate::setEditorData) that handles this particular case?<br>
&gt;<br>
&gt; 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">&gt;<br>
&gt; 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