1

I have a plugin that works with QGIS 2.2 but does not work with 2.8. Only deleteFeatures() works fine, but changeAttributeValues(), changeGeometryValues() and addFeatures() not.

I receive r == False on the code below. The layer is an SpatiaLite table.

for feat_vias in lay_vias.getFeatures(req):

    if  feat_vias.attributes()[idx_pkvia] == div_rowid:
        fid = feat_vias.id()
        attrs = { idx_setvia : s_geocodi }
        r = lay_vias.dataProvider().changeAttributeValues({ fid : attrs })

I'm using QGIS 2.8.1 - Windows

In another question (Speed of editing attributes in QGIS from a Python plugin) I found an Matthias Kuhn's answer that solve this question too.

I put the commit sentence outside the loop as below. Work fine!

for feat_vias in lay_vias.getFeatures(req):

    if  feat_vias.attributes()[idx_pkvia] == div_rowid:
        fid = feat_vias.id()
        attrs[fid] = { idx_setvia : s_geocodi }

r = lay_vias.dataProvider().changeAttributeValues(attrs)
1
  • The problem was not the same but the solution is. However, I think the question can be excluded without problems.
    – Sassá
    Jul 16, 2015 at 14:48

0

Browse other questions tagged or ask your own question.