Hi, I resolved !
The solution was: for idx, fld in enumerate(layer.dataProvider().fields()): and after in the code retrieve the alias (or the fieldname) using: layer.attributeDisplayName(idx) and the real name of the field using: fld.name() Thx for help. 2015-11-02 16:32 GMT+01:00 Andrea Peri <aperi2...@gmail.com>: > Hi, > > yes , my goal was to retrieve the aliases. > > To reach this information I plan to use this function: > > fldDescr = fld.attributeDisplayName() > > The attributeAlias give me the aliases when availables, but when they > are not filled it return a null (or empty) string. > Instead the attributeDisplayName() return the Alias or the original FieldName. > > A. > > > 2015-11-02 15:28 GMT+01:00 Matthias Kuhn <matth...@opengis.ch>: >> Hi >> >> layer.attributeList() works for me, I really don't know what goes wrong >> there for you. But it's a quite silly functions since the attribute >> indexes were changed to always be sequential. Now it just delivers a >> list each numbers from 0..count-1. So your enumerate will allways give >> you [(0,0)..(n-1, n-1)]. >> >> That said, what you probably want to use is layer.attributeAliases(). >> That gives you a mapping of field names to aliases. >> Or [(idx, layer.attributeAlias(idx)) for idx in >> range(layer.fields().count())] if you really want to use the field indexes. >> >> Best, >> Matthias >> >> On 11/02/2015 02:28 PM, Andrea Peri wrote: >>> Hi, >>> >>> I need to retrieve a list of attribute alias. >>> To do this, I try this code: >>> >>> for lid, orientation in self.templateTable.model().getObjectIter(): >>> layer = QgsMapLayerRegistry.instance().mapLayer(lid) >>> for idx, fld in enumerate(layer.attributeList()): >>> ... >>> >>> The qgis report me this error: >>> >>> for idx, fld in enumerate(layer.attributeList()): >>> AttributeError: 'QgsVectorLayer' object has no attribute 'attributeList' >>> >>> But I see the AttributeList is available in that clas as reported from the >>> help. >>> >>> http://www.qgis.org/api/classQgsVectorLayer.html#a9fdee4a58551d7e1424c8f66ab6c14a0 >>> >>> Perhaps I'm wrong something or the documentation API is obsolete ? >>> >>> Thx. >>> >>> >>> >> >> >> >> _______________________________________________ >> Qgis-user mailing list >> Qgis-user@lists.osgeo.org >> http://lists.osgeo.org/mailman/listinfo/qgis-user > > > > -- > ----------------- > Andrea Peri > . . . . . . . . . > qwerty àèìòù > ----------------- -- ----------------- Andrea Peri . . . . . . . . . qwerty àèìòù ----------------- _______________________________________________ Qgis-user mailing list Qgis-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-user