On Mon, Aug 22, 2016 at 7:57 PM, Casper Børgesen (CABO) <c...@niras.dk> wrote: > I have added a layer to the layer tree and now I want to remove it from the > layer tree: > > self.layer = self.create_my_layer() > QgsProject.instance().layerTreeRoot().insertLayer(0, self.layer) > QgsProject.instance().layerTreeRoot().removeLayer(self.layer) > > But it seems like my layer has been destroyed while removing it from the > layer tree. Is it possible to not destroy the layer while still removing it > from the tree?
It is possible - just temporarily disable the bridge to map layer registry before removing the layer: QgsProject.instance().layerTreeRegistryBridge().setEnabled(False) ... and then enable it again. You should make sure to remove the layer from the map layer registry later when you have finished using it. Otherwise if user saves the project, that layer will still be referenced (and loaded when the project loads) but it will not be accessible from the GUI. Cheers Martin _______________________________________________ Qgis-developer mailing list Qgis-developer@lists.osgeo.org List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer