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

Ricardo Araoz ricaraoz at gmail.com
Wed May 9 14:53:10 BST 2018



On 09/05/18 05:57, Phil Thompson wrote:
>>>
>>>>> def data(self, index: QtCore.QModelIndex, role=QtCore.Qt.DisplayRole) -> typing.Any:
>>>>>      was_enabled = sip.enableautoconversion(QtCore.QVariant, False)
>>>>>      value = super().data(index, role)
>>>>>      sip.enableautoconversion(QtCore.QVariant, was_enabled)
>>>>>      return value
>>
>  From your Python data() you call the C++ data(). This returns a QVariant to PyQt. With auto-conversion enabled this is converted to a Python value before being passed back to your Python data(). This loses the null information. Your Python data() then returns this value. The C++ code that invoked it requires a QVariant so (with auto-conversion enabled) PyQt first converts it back to a QVariant.
>
> The only way to keep the null information is to disable auto-conversion. This means that the object that your Python data() got back from calling the C++ data() is the QVariant (with intact null information). You then return this and it then makes its way back to the invoking C++.
>
> Phil
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt

Sorry to chime in but I also don't completely get it.
AFAIK the call to super() should return a reference to the parent class, 
that is pyqt's QSqlQueryModel, not the C++ class. And in case there is a 
reason for that (which I'm sure there is), is there a way to call the 
pyqt parent class' data() method and not the c++ method?
Isn't there a way to call the pyqt method so that IT may call the c++ 
method and all would be nice? (I don't know, would 
"super(QSqlQueryModel, self).data()" do the trick?)

In case there isn't, would there be a way to call the conversion method 
pyqt's data() class uses and feed it the c++ data() results so that they 
are properly converted in the same way it's done originally?

Because I understand Jonathan's concern that he wants a way to replicate 
what would be going on if he hadn't subclassed the method.

TIA

Ricardo



More information about the PyQt mailing list