[QGIS-trac] Re: [Quantum GIS] #3713: Memory layer's fields not shown in attribute table (and layer properties) unless refreshed by entering the edit mode

Quantum GIS qgis at qgis.org
Fri Apr 8 19:33:35 EDT 2011


#3713: Memory layer's fields not shown in attribute table (and layer properties)
unless refreshed by entering the edit mode
------------------------------------------------+---------------------------
   Reporter:  borysiasty                        |              Owner:               
       Type:  bug                               |             Status:  new          
   Priority:  major: does not work as expected  |          Milestone:  Version 1.7.0
  Component:  Vectors                           |            Version:  Trunk        
   Keywords:                                    |   Platform_version:               
   Platform:  Debian                            |           Must_fix:  Yes          
Status_info:  0                                 |  
------------------------------------------------+---------------------------

Comment(by jef):

 Replying to [ticket:3713 borysiasty]:
 > Please note in the python console I can see the fields and attributes.

 You can only see the fields of the provider.  The layer doesn't have any -
 yet.

 But following works fine:

 {{{
 layer = QgsVectorLayer("Point","mylayer","memory")
 QgsMapLayerRegistry.instance().addMapLayer(layer)
 layer.startEditing()
 layer.addAttribute( QgsField("foo", 2, "integer", 5) )
 f = QgsFeature()
 f.setGeometry(QgsGeometry.fromPoint(QgsPoint(0,0)))
 f.setAttributeMap( { 0 : 2 } )
 layer.addFeature( f )
 layer.commitChanges()
 }}}

-- 
Ticket URL: <https://trac.osgeo.org/qgis/ticket/3713#comment:1>
Quantum GIS <http://qgis.org>
Quantum GIS is an Open Source GIS viewer/editor supporting OGR, PostGIS, and GRASS formats


More information about the QGIS-trac mailing list