I am developing a plugin, and I want user to select one of the loaded layers from a combobox. I've already coded this much:
self.dlg.show() layerlist =  self.dlg.ui.layerCombo.clear() # clear the combo layermap = QgsMapLayerRegistry.instance().mapLayers() for name, layer in layermap.iteritems(): if layer.type() == QgsMapLayer.VectorLayer: if layer.geometryType() == QGis.Line: layerlist.append( unicode( layer.name() ) ) for layer in layerlist: # foreach layer in legend self.dlg.ui.layerCombo.addItem( layer )
First Question: I get the error
IndexError: list index out of range
which I don't quite know why.
Second Question: Am I doing the right thing? I couldn't find a tutorial on this. Where is the best place to put this code (run, initGui,...)?
Any help is greatly appreciated!