[PyQt] PyQt 5.7, QSqlQueryModel.data() sub-classed override bug?
phil at riverbankcomputing.com
Thu May 3 16:17:20 BST 2018
On 3 May 2018, at 3:22 pm, J Barchan <jnbarchan at gmail.com> wrote:
> Hey Phil,
> Assuming I am not barking up the wrong tree, I see you yourself were discussing this issue in http://python.6.x6.nabble.com/PyQt5-NULL-QVariant-tp5188782p5190811.html. It includes:
> > Can you confirm that returning empty string and 0 for NULL is expected
> > behavior and not seen as a bug?
> Yes. If you want to distinguish null QVariants then use sip.enableautoconversion(). The problem is that you are not willing to do that.
> So I'm bumbling around trying to put a sip.enableautoconversion() in! Trouble is, I don't understand the syntax, and I don't know where to put it (I'm not finding any examples, and you two obviously knew more than me about it :) )
> 1. I'm assuming I want to suppress converting QVariants. I'm trying
> sip.enableautoconversion(QVariant, False)
> but it doesn't know what QVariant is, and I don't know if it's supposed to or my syntax or imports or whatever?
Import QVariant from QtCore.
> 2. I don't know where I'm supposed to disable & re-enable the autoconversion? My method is an override called implicitly by Qt.
> * Is this a "directive" that's supposed to be used e.g. as a Python method is read in, and so belongs around the whole function?
> * Is this a "run-time* that I just need to put inside my method overload around where it calls the base class method? Or by the time it has hit my overload is it too late because some conversion has already happened?
> * Do I actually need to put it around the whole of my top-level call to, say, QSqlQueryModel.rowCount(), which is what (I understand to be) invoking calls to the overridden QSqlQueryModel.data() method?
I think you need to do the latter - at least as a workaround for the moment. I need to add a directive to SIP to disable the auto-conversion during the code that handles the virtual and calls the Python re-implementation.
More information about the PyQt