[Qgis-developer] QGIS crashes when doing a rollback after modifying values of an user-added feature with pyQGIS

John Stevenson john.stevenson at thinkwhere.com
Mon Mar 7 00:40:25 PST 2016

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:



John Stevenson
Senior Developer
Email:mailto:john.stevenson at thinkwhere.com

Glendevon House
Castle Business Park
Stirling FK9 4TZ

Tel: 01786 476060
Tel: 01786 476093 (Direct Dial)

From: Qgis-developer [qgis-developer-bounces at lists.osgeo.org] on behalf of Martin Dobias [wonder.sk at gmail.com]
Sent: 06 March 2016 08:52
To: Manuel Hernández Martínez
Cc: Qgis-developer at 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
<mhernandezm at 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

Qgis-developer mailing list
Qgis-developer at lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

More information about the Qgis-developer mailing list