[PyQt] modeltest.py for PyQt5?

Nenad Ognjanovic bgr.gyk at gmail.com
Wed Aug 13 15:04:46 BST 2014


I've noticed that modeltest.py is no longer present in PyQt source.
Since I've started porting the old one to PyQt5, I'm interested in knowing
if there was any reason for excluding it in the first place, other than not
being compatible anymore?
Also, a good question at this point would be: does a PyQt5 version of
modeltest.py already exist?

The most recent one I've managed to find is the PyQt4 version from tortoisehg
repository. I've started porting this version to PyQt5, but I've quickly hit
a bump. I'd like to know if anyone here is interested in helping to get this
ported, since I'm not familiar with the internals of Qt/PyQt/sip.

The source can be found at: https://github.com/bgr/PyQt5_modeltest
Not much was changed so far.

The first problem I've encountered happens at this point:
https://github.com/bgr/PyQt5_modeltest/blob/ea9a34a0/modeltest.py#L238-L239
with the following error:

    AttributeError: 'NoneType' object has no attribute 'isValid'

I've identified that this happens due to sip.cast at line #44, which causes
the returned QVariant to be converted into None. When the line #238 is
changed to access the original self._model directly, the QVariant is returned
correctly.

However, if I remove the cast altogether, I get the following error:

    File ".../modeltest.py", line 78, in nonDestructiveBasicTest
        assert(self.model.columnCount(QtCore.QModelIndex()) >= 0)
    TypeError: QAbstractListModel.columnCount() is a private method

I guess that sip.cast is there specifically because of this, to un-private
the methods.

Any advices on how to approach this? Would it be correct to just switch
between accessing cast and original models as needed?
Also, any other hints and gotchas that I should be aware of are welcome.


More information about the PyQt mailing list