Hi Manuel, I struggled with a similar problem. Another possible workaround is waiting until the user has saved their edits. You can then catch the commitedFeaturesAdded signal and update the layer directly using the provider. This method has the advantage that the fid that refers to the feature at this stage is the final one and does not change.
See this Stack Overflow page for more info: http://gis.stackexchange.com/questions/176686/automatically-updating-user-edited-features-in-qgis-plugin/177594#177594 Cheers John John Stevenson Senior Developer Email:mailto:john.steven...@thinkwhere.com Glendevon House Castle Business Park Stirling FK9 4TZ Tel: 01786 476060 Tel: 01786 476093 (Direct Dial) ________________________________________ From: Qgis-developer [qgis-developer-boun...@lists.osgeo.org] on behalf of Martin Dobias [wonder...@gmail.com] Sent: 06 March 2016 08:52 To: Manuel Hernández Martínez Cc: Qgis-developer@lists.osgeo.org Subject: Re: [Qgis-developer] QGIS crashes when doing a rollback after modifying values of an user-added feature with pyQGIS Hi Manuel On Fri, Mar 4, 2016 at 10:05 PM, Manuel Hernández Martínez <mhernand...@agenciamedioambienteyagua.es> wrote: > > self.iface.mapCanvas().currentLayer().featureAdded.connect(self._debug_onFeatureAdded) > > def _debug_onFeatureAdded(self, fid): > layer = self.iface.mapCanvas().currentLayer() > layer.beginEditCommand("Set UUID") > print layer.changeAttributeValue(fid, > layer.fieldNameIndex('guid_pol'), 'some_random_uuid') # prints True > layer.endEditCommand() > > [...] > > When I edit the layer, if I add a feature the field 'guid_pol' is set to > 'some_random_uuid' as expected. I can commit the changes without a problem, > however if instead of committing the changes I try cancelling them QGIS > crashes with error 0xC0000005 (Access Violation). Unfortunately this is currently a limitation of our current editing system... When an editing signal (like "featureAdded") is emitted, doing some extra editing actions will corrupt the undo stack because the undo command of the previous action is not yet finished. A possible workaround could be to use queued signal/slot connection instead of direct connection (which is the default), so the slot execution will be delayed, and the undo stack will get to a consistent state. Regards Martin _______________________________________________ Qgis-developer mailing list Qgis-developer@lists.osgeo.org List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer _______________________________________________ Qgis-developer mailing list Qgis-developer@lists.osgeo.org List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer