1

This question already has an answer here:

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)

marked as duplicate by Germán Carrillo, Brad Nesom, Jason Scheirer, whuber Jul 15 '15 at 20:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • The problem was not the same but the solution is. However, I think the question can be excluded without problems. – Sassá Jul 16 '15 at 14:48