[Qgis-developer] PyQt4.QtCore.QVariant represents a mapped type and cannot be instantiated

Mark Coletti mcoletti at gmail.com
Wed Oct 1 13:55:34 PDT 2014


I'm writing a qgis python plugin and have encountered a curious problem.
I've successfully tested the plugin's dialog standalone via ipython.
However, I get the following error when I try to execute the same code from
within qgis: "PyQt4.QtCore.QVariant represents a mapped type and cannot be
instantiated".

The error occurs from within a QAbstractTableModel subclass, specifically
the headerData function, which is given below:

    def headerData(self, section, orientation, role):
        if role == Qt.DisplayRole :
            if orientation == Qt.Horizontal :
                return QVariant(self.headers[section])
            elif orientation == Qt.Vertical :
                return QVariant(self.events[section].categoryID)
        return QVariant()

As far as I can tell, that's pretty much textbook PyQt.  I've found a similar
problem
<http://stackoverflow.com/questions/10382025/qvariant-in-qcombobox-python-2-vs-python-3>,
but that was a python 2 vs. 3 scenario, and this is all within the python
2.7.1 domain.

I've tried to code up a workaround where I just return empty strings and
that leads to all sorts of havok.  The table is rendered, but the header
columns are missing and there are undesired check boxes in all the table
cells.

Has anyone else encountered this problem?  Or otherwise knows what's going
on?

Cheers!

Mark
-- 
mcoletti at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20141001/e6a655c0/attachment.html>


More information about the Qgis-developer mailing list