[Qgis-developer] updating multiple attribute values at once
Martin Dobias
wonder.sk at gmail.com
Sat Apr 30 12:21:11 EDT 2011
Hi Karsten
On Sat, Apr 23, 2011 at 10:44 AM, karsten vennemann
<karsten at terragis.net> wrote:
> I am trying to update multiple values in an edit session via python
>
> mc = self.canvas
> layer = mc.currentLayer()
> provider = layer.dataProvider()
> ob = layer.selectedFeaturesIds()
> fid = int(ob[0])
> newvalues = { fid : { 3 : "lima", 4 : "city"}}
> provider.changeAttributeValues(newvalues)
>
> However I am not getting an error nor does the update of the selected
> feature take place.
> What is wrong with my code ?
You should wrap the values into QVariant type from PyQt4.QtCore like this:
newvalues = { fid : { 3 : QVariant("lima"), 4 : QVariant("city") }}
Your original code actually crashes on my computer, there is something
wrong with the conversion Python -> QGIS conversion when not wrapping
the values into QVariant. I will probably have a closer look into
that.
Regards
Martin
More information about the Qgis-developer
mailing list