[Qgis-developer] best to add a feature on a layer (+ crash)

Denis Rouzaud denis.rouzaud at gmail.com
Tue Apr 2 22:55:17 PDT 2013


Perfect Nathan, thanks a lot.


On 04/03/2013 07:44 AM, Nathan Woodrow wrote:
> Denis,
>
> You didn't tell QgsFeature how many attributes it has.  You can call 
> initAttributes(1) or pass in the QgsFields into QgsFeature(fields)
>
> - Nathan
>
>
> On Wed, Apr 3, 2013 at 3:42 PM, Denis Rouzaud <denis.rouzaud at gmail.com 
> <mailto:denis.rouzaud at gmail.com>> wrote:
>
>     Hi all,
>
>     I try to add a feature in a layer with only one field (over a few
>     in the layer) filled.
>
>     Here is what I tried:
>
>     f = QgsFeature()
>     f.setGeometry(myGeom)
>     f.setAttribute(1, myValue)
>     provider.addFeatures( [f] )
>
>     This causes QGIS to crash.
>
>     What did I wrong? I should not set field 1 if there is a field 0
>     in my feature?
>     Should I set the same number of fields as present in the layer?
>     Is there another way to achieve this?
>
>     Thanks a lot,
>
>     Denis
>
>
>
>
>     _______________________________________________
>     Qgis-developer mailing list
>     Qgis-developer at lists.osgeo.org <mailto:Qgis-developer at lists.osgeo.org>
>     http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20130403/a3687f3b/attachment.html>


More information about the Qgis-developer mailing list