I'm trying to change attribute values in a memory layer. My memory layer is defined in this way:

pro.addAttributes([QgsField("nom", QVariant.String), QgsField("valeur", QVariant.Int)])

I made several tries:

attrs = { 0 : "hello"}
bFlag3=vl.dataProvider().changeAttributeValues({ fet.id() : attrs })

Or in this way :


Each time my boolean flag returns True but I never see any change in my memory table. I make a


in both cases.

When I try these two pieces of code on the two other layers (which aren't memory layers...) I have in my project, I see the attributes change...

Can anyone help me troubleshoot this?

  • In fact i just noticed that i'm not able to (manually) modify the fields of this (programmatically created) memory layer in QGIS interface ... Any hint ? – snaileater Aug 7 '14 at 12:35

Your code seems correct, but you are missing one line of code:


This is not necessary when you edit a layer and then closes it, as it will show correctly when you load it again, but it is necessary if you want to use/see it in the same session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.