I'm new to QGIS python development. I'm trying to create new features in an existing vector layer and then to display the Feature Form so that the user can fill the attribute values.
The problem is, after the code is executed (after I fill the features atribute values and click Ok), an error is shown: Feature 0 for attribute update not found.
After that, I run again the code to create another feature with different attribute values. No error appears, but I notice that the attribute values from the firts created feature are exact like the attribute values from the second created feature.
Here is the code:
mylayer = QgsProject.instance().mapLayersByName('my layer name') mylayer.startEditing() feat = QgsFeature () feat.setFields(mylayer.fields()) //here is the code that creates the geometry// feat.setGeometry(geom) self.iface.openFeatureForm(mylayer, feat, False) mylayer.addFeature(feat) mylayer.commitChanges()
What am I doing wrong? I don't know if it helps, but mylayer is an empty layer.