I have this piece of code which I would like to use for inserting values into a column. It does not throw an error, the changes are not written to the source (shapefile).
from qgis.utils import iface
from PyQt4.QtCore import *
layers = iface.legendInterface().layers()
for layer in layers:
name = layer.name()
if name.endswith('x'):
provider = layer.dataProvider()
features = provider.getFeatures()
for feature in features:
feature.setAttribute('attr', 'a')
I understood there are two ways of editing data sources: directly with dataProvider or with edit buffer. If I got it right, it shouldn't be necessary to call commit action when using dataProvider.
I'm using QGIS 2.2 Valmiera.