[Qgis-developer] PyQt4.QtCore.QVariant represents a mapped type and cannot be instantiated
Gary Sherman
gsherman at geoapt.com
Wed Oct 1 14:06:12 PDT 2014
On 10/1/14 12:55 PM, Mark Coletti wrote:
> 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".
>
Your answer is here:
http://hub.qgis.org/wiki/quantum-gis/Python_plugin_API_changes_from_18_to_20
QVariant is no longer present in QGIS since we use the sip 2.0 api.
Use regular strings rather than a QVariant.
> 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 <mailto:mcoletti at gmail.com>
>
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Gary Sherman
Founder, QGIS Project
Consulting: geoapt.com
Publishing: locatepress.com
We work virtually anywhere
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
More information about the Qgis-developer
mailing list