QgsFeature feature; QgsFields fields; fields.append(QgsField("name", QVariant::String)); fields.append(QgsField("age", QVariant::Int)); feature.setFields(fields); feature.setAttribute("name", "John Doe"); feature.setAttribute("age", 30); QgsVectorLayer* layer = new QgsVectorLayer("Point", "my layer", "memory"); layer->startEditing(); layer->addFeature(feature); layer->commitChanges();
QgsVectorLayer* layer = new QgsVectorLayer("Point", "my layer", "memory"); QgsFeatureIterator it = layer->getFeatures(); while (it.hasNext()) { QgsFeature feature = it.next(); feature.setAttribute("age", feature.attribute("age").toInt() + 1); layer->updateFeature(feature); }In this example, we create a vector layer in memory, iterate over its features, update the "age" attribute of each feature by increasing it by 1, and save the changes using updateFeature() method. These examples use the QGIS C++ API library.