<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 9 May 2018 at 15:36, J Barchan <span dir="ltr"><<a href="mailto:jnbarchan@gmail.com" target="_blank">jnbarchan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-family:tahoma,sans-serif"></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On 9 May 2018 at 14:53, Ricardo Araoz <span dir="ltr"><<a href="mailto:ricaraoz@gmail.com" target="_blank">ricaraoz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span><br>
<br>
On 09/05/18 05:57, Phil Thompson wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">
def data(self, index: QtCore.QModelIndex, role=QtCore.Qt.DisplayRole) -> typing.Any:<br>
was_enabled = sip.enableautoconversion(QtCor<wbr>e.QVariant, False)<br>
value = super().data(index, role)<br>
sip.enableautoconversion(QtCo<wbr>re.QVariant, was_enabled)<br>
return value<br>
</blockquote></blockquote></blockquote>
<br>
</blockquote></span><span>
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.<br>
<br>
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++.<br>
<br>
Phil<br></span>
______________________________<wbr>_________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.riverbankcomputing<wbr>.com/mailman/listinfo/pyqt</a><br>
</blockquote>
<br>
Sorry to chime in but I also don't completely get it.<br>
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?<br>
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?)<br>
<br>
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?<br>
<br>
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.<br>
<br>
TIA<br>
<br>
Ricardo<br>
<br>
______________________________<wbr>_________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.riverbankcomputing<wbr>.com/mailman/listinfo/pyqt</a></blockquote></div><br></div></div><div style="font-family:tahoma,sans-serif">Thanks for your moral support, Ricardo! We shall see what Phil has to say, as only he can answer this.</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">For my own part, having finally understood what was necessary, with great regret I am abandoning my whole PyQt sub-classing of this method and just having to manage without. The outcome was that the <i>caller</i> code has to be changed to either execute <font face="monospace,monospace">.value()</font> on every result (iff I do the sub-classing, which has to suppress the auto-conversion, and returns a <font face="monospace,monospace">QVariant</font>), or not to do <font face="monospace,monospace">.value()</font> (iff, say, I decide to get rid of my override at some point, and it returns native type). The two are incompatible, and technically it is not possible to write calling code which works regardless of whether there is sub-classing going on. I can see it's not PyQt/Phil's "fault", but that is very strange behaviour to accept in overriding a method, it would be expected to behave identically. I do not wish to carry that burden in my code, and/or have to change hundreds of callers in existing code.</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">I'll keep an eye out in case Phil has something to say about your suggestions, as you guys understand much better than I.</div><span class="HOEnZb"><font color="#888888"><br clear="all"><br>-- <br><div class="m_-6724005040872717317gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div>
</font></span></div></div>
</blockquote></div><br><div style="font-family:tahoma,sans-serif" class="gmail_default">Hi Phil,</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">Sorry, but I have one more related question about surprise behaviour. I will try to keep this as brief as possible.</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">Yesterday I came to understand why overriding, say, <span style="font-family:monospace,monospace">QSqlTableModel.data()</span> came to grief on database-<span style="font-family:monospace,monospace">NULL</span>, because of the Python loss of distinction on the <span style="font-family:monospace,monospace">QVariant</span>s representing "null" versus "default/invalid". I would get back the "default" value where I expected the "null" value.<br></div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">In sorting my code out now in that light, I began to assume that <span style="font-family:monospace,monospace">QSqlTableModel.setData(index, None)</span> would effectively suffer from exactly the same problem, in the opposite direction, i.e. it would set it to the "default" value not the "null" one. And so I would need to deal with too.</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">However, I find that, <i>whether I do or do not override</i> (in similar fashion) <span style="font-family:monospace,monospace">QSqlTableModel.setData(index: QModelIndex, value: QVariant)</span> it <i>does</i> set the value to database-NULL when called via <span style="font-family:monospace,monospace">.setData(index, None)</span>.</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">This surprises me, as I expected it to have the same <span style="font-family:monospace,monospace">QVariant</span> conversion issue over <span style="font-family:monospace,monospace">None</span> as <span style="font-family:monospace,monospace">data(index)</span> would. Would you care to explain why this does <i>not</i> appear to be the symmetrical problematic case?</div><div style="font-family:tahoma,sans-serif" class="gmail_default"><br></div><div style="font-family:tahoma,sans-serif" class="gmail_default">Thank you in advance of your reply.<br></div><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div>
</div></div>