I managed to add QgsVectorLayer
in QGIS
through a python plugin, for example:
vl = self.iface.addVectorLayer(uri.uri(), layerName, self.dbConn.getProviderName())
But how can I remove it?
Answer
Are you on QGIS 1.8? If so, you can remove your vl
with:
QgsMapLayerRegistry.instance().removeMapLayers( [vl.id()] )
otherwise:
QgsMapLayerRegistry.instance().removeMapLayer( vl.id() )
And if you are on QGIS 3.0+, replace QgsMapLayerRegistry
with QgsProject
.
Or if by chance you want to remove all empty layers, check out the Remove Empty Layers plugin.
No comments:
Post a Comment