Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 8 down vote accepted

Are you on QGIS 1.8? If so, you can remove your vl with:

QgsMapLayerRegistry.instance().removeMapLayers( [] )


QgsMapLayerRegistry.instance().removeMapLayer( )

Or if by chance you want to remove all empty layers, check out the Remove Empty Layers plugin.

share|improve this answer
thanks for the answer.. I'll try as soon as possible – Heisenbug Nov 27 '12 at 18:29
ok -- note that I just edited the answer to use your vl variable. – andytilia Nov 27 '12 at 18:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.