[Qgis-developer] remove layer from QgsMapLayerRegistry

Martin Dobias wonder.sk at gmail.com
Thu Dec 18 11:26:01 EST 2008


On Mon, Dec 15, 2008 at 3:43 PM, piko <piklas at gmail.com> wrote:
>
> Folks
>
> in one of my plugin , i create a layer, add it to canvas and then need to
> remove it both from canvas and from layer registry, with this code:
>
> QgsMapLayerRegistry.instance().removeMapLayer(self.sprayerLayer.getLayerID())
>
> The layer is deleted from canvas but not from the layer registry.
> Do you know why ?
>
> Is there another way to update the registry ?

I'm unable to replicate your problem. My test case:
- open a layer in QGIS
- open python console:
>>> id = iface.mapCanvas().currentLayer().getLayerID()
>>> QgsMapLayerRegistry.instance().mapLayers()
(prints a dictionary with QString keys and map layers as values)
>>> QgsMapLayerRegistry.instance().removeMapLayer(id)
(layer is removed from legend and canvas)
>>> QgsMapLayerRegistry.instance().mapLayers()
(prints empty dictionary)


Martin


More information about the Qgis-developer mailing list