[PyQt] PyQt 5.7, QSqlQueryModel.data() sub-classed override bug?
hpj at urpla.net
Tue May 8 21:59:24 BST 2018
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
> 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
> 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) ->
> 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.
More information about the PyQt