Bug report #20723

QgsVectorLayer.featuresDeleted signal not emitted when deleting features programatically

Added by Matthew Jurewicz almost 6 years ago. Updated almost 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Python bindings / sipify
Affected QGIS version:3.4.2 Regression?:No
Operating System:Windows 10 Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:28543

Description

The following Python code doesn't log any messages:

def this_is_a_test():
QgsMessageLog.logMessage('this is a test')

iface.activeLayer().featuresDeleted.connect(this_is_a_test)

iface.activeLayer().dataProvider().deleteFeatures([1])

History

#1 Updated by Alessandro Pasotti almost 6 years ago

  • Resolution set to invalid
  • Status changed from Open to Closed

If you use directly the data provider you have no signals, the recommended way is using the editing buffer:

iface.activeLayer().startEditing()
iface.activeLayer().dataProvider().deleteFeatures([1])
iface.activeLayer().commitChanges()

Also, check the signature of the signal: it sends a QSet of feature ids.

Also available in: Atom PDF