[Qgis-developer] Can`t add feature to QgsVectorLayer

hubbatov hubbatov at mail.ru
Mon Oct 28 06:00:58 PDT 2013


I have this example, that worked in QGis 1.8 but in QGis 2.0 don`t. What i`m
doing wrong?

QgsFields fields;
fields.append(QgsField("id", QVariant::String, "id"));
fields.append(QgsField("name", QVariant::String, "name"));

QgsFeature feature = QgsFeature(fields);

qDebug() << "Add Attr" << feature.setAttribute("name", field->name()); <====
true
qDebug() << "Add Attr" << feature.setAttribute("id",
field->id().toString()); <==== true

QgsGeometry* geom = QgsGeometry::fromPolygon(fieldPolygon());

if (geom)  {
	feature.setGeometry(QgsGeometry::fromPolygon(fieldPolygon())); <==== valid
geometry
} else {
	feature.setGeometry(QgsGeometry::fromPoint(QgsPoint(0,0)));
}

qDebug() << "Feature is valid:" << feature.isValid(); <==== feature is not
valid, QgsFeature::setValid(true) not helped

if (!m_layer->addFeatures(QgsFeatureList() << feature)) {
	qDebug() << "FieldEntity#Error add field feature"; <====== Can`t add
feature
}
m_layer->commitChanges();



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Can-t-add-feature-to-QgsVectorLayer-tp5086078.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list