QgsVectorLayer *layer = new QgsVectorLayer("/path/to/shapefile", "layer_name", "ogr"); layer->startEditing(); QgsEditCommand *editCommand = layer->beginEditCommand("Add new feature"); // Do some editing layer->commitChanges();
QgsVectorLayer *layer = new QgsVectorLayer("/path/to/shapefile", "layer_name", "ogr"); layer->startEditing(); QgsFeature feature; feature.setGeometry(QgsGeometry::fromWkt("POINT(1 1)")); layer->addFeature(feature); layer->undoStack()->push(layer->beginEditCommand("Add new feature")); layer->commitChanges();In this example, a new feature is added to the layer, and an edit command is initiated using the beginEditCommand method. The edit command is then pushed onto the undo stack, and changes made to the layer are committed. Package library: QGIS API Overall, QgsVectorLayer beginEditCommand is a useful method for initiating edit commands that can be used to undo or redo changes made to vector layers in QGIS. It is part of the QGIS API library.