[Qgis-developer] Problem using QgsFeature.attributes() instead of QgsFeature.attributeMap() in QGIS 1.9

Martin Dobias wonder.sk at gmail.com
Wed Mar 13 13:48:49 PDT 2013


Hi Alexandre

On Tue, Mar 12, 2013 at 1:22 AM, Alexandre Neto <senhor.neto at gmail.com> wrote:
> ...
> new_attributes = layer.pendingFields()
>
> [...]
>
> But when using it in 1.9 I got the following error in the line:
> new_attributes[j] = feature.attributes()[j]
>
> Traceback (most recent call last):
>   File "<input>", line x, in <module>
> TypeError: QgsFields.__setitem__(): argument 2 has unexpected type
> 'QVariant'

What are you actually trying to do?

layer.pendingFields() returns QgsFields instance, which basically acts
as a list of QgsField instances (attribute definitions). Then, you are
trying to assign an attribute value (QVariant) to a field - that's
clearly an error and it is reported correctly. Probably you want to
copy the attributes to another feature?

Martin


More information about the Qgis-developer mailing list