[PyQt] PyQt 5.7, QSqlQueryModel.data() sub-classed override bug?

J Barchan jnbarchan at gmail.com
Wed May 9 07:56:32 BST 2018


​

On 8 May 2018 at 21:59, Hans-Peter Jansen <hpj at urpla.net> wrote:

> Hi Jonathan,
>
> On Dienstag, 8. Mai 2018 20:22:12 J Barchan wrote:
>
> > > You can't have it both ways. Either you let PyQt automatically convert
> > > to/from QVariant (and you lose the detection of nulls) or you do it
> > > yourself (converting to Python using the value() method).
> >
> > I'm not asking to have anything both ways.​  I'm just asking how to write
> > code so that the overridden method behaves *absolutely identically* to
> the
> > base method it's overriding.  Surely that must be possible?
> >
> > I remind you: when I have no override for ​QSqlQueryModel.data()
> *everything
> > behaves perfectly*.  I am saying: there is no problem, NULLs are handled
> as
> > such and non-NULLs are correctly converted to their Python equivalent.  I
> > do not know how NULLs work (what they are returned as), but everything
> just
> > works.
> >
> > As soon as I write an override which just returns the base method, it
> goes
> > wrong on NULL.  If I put it the sip.autoconversion(False), it works on
> NULL
> > but now returns a QVariant where it used to return a Python native type,
> I
> > think.
> >
> > All I want to know is: how can I write an override of  ​
> > QSqlQueryModel.data() in Python/PyQt like:
> >
> > def data(self, index: QtCore.QModelIndex, role=QtCore.Qt.DisplayRole) ->
> > typing.Any:
> >      value = super().data(index, role)
> >      return value
> >
> > such that it returns *just exactly the same as* QSqlQueryModel.data()
> would
> > have done, please, please, please?
>
> Well, in a perfect world, you would get what you want, but we don't live
> in a
> perfect world... What hinders you to
> ​​
> convert any QVariant yourself?
>
> It's
> ​​
> additional one or two lines of code per type, or, if it is getting too
> "spagetti", a dict "switch" with type as key.
>
> Cheers,
> Pete
>

​Precisely because I don't know how to ​"​convert any QVariant yourself"?
Because I don't mind "​additional one or two lines of code per type", or a
switch, or whatever, but I don't know what those lines of codes are
supposed to be?  Maybe you do, but I'm sorry I do not, that's what I'm
asking.....


-- 
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180509/071fd9b9/attachment.html>


More information about the PyQt mailing list