[Qgis-user] Adding attributes to a layer with "memory" provider

Václav Řehák rehakv01 at gmail.com
Mon Apr 19 05:19:39 PDT 2010


Hi,

in my plugin I create a layer using the following code:

self.lines = QgsVectorLayer("LineString", "temporary_lines", "memory")
self.lines.startEditing()
field = QgsField("label", QVariant.String)
field.setLength(100)
ret = self.lines.addAttribute(field)
QgsMapLayerRegistry.instance().addMapLayer(self.lines)
self.lines.commitChanges()

However, the field is not added to the layer and "ret" is false. I realized
I am not even able to add the attribute in the GUI using layer Properties
dialog - the Type dropdown in Attributes - Add column window is empty. Is it
bug or a feature that I cannot add attributes to memory layer?

I'm using 1.4.0 on Windows XP.

Thanks for help.

Vaclav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20100419/737c40f9/attachment.html>


More information about the Qgis-user mailing list