Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am developing a Qgis plugin (layer_gui) and I am having a problem with populating the list of layers. When I first run the plugin my combo boxes are not filled with a list of layers, I have to reload the plugin to get them to fill in. I am sure I do not have the correct sequence of events.

Source Code from class layer_gui:

def __init__(self, iface):
    # Typical stuff from plugin builder

def initGui(self):
    # Typical stuff from plugin builder

def unload(self):
    # Typical stuff from plugin builder

# run method that performs all the real work
def run(self):
    # show the dialog
    # Run the dialog event loop
    result = self.dlg.exec_()
    # See if OK was pressed
    if result == 1:
        input_source_layer = unicode( self.dlg.ui.source_layer_cb.currentText() )  
        input_dest_layer = unicode( self.dlg.ui.dest_layer_cb.currentText() )  
        QMessageBox.information(None, "Dangling Nodes:", str(input_source_layer) + " -- " + str(input_dest_layer))

Source Code from

def __init__(self):
    # Set up the user interface from Designer.
    self.ui = Ui_layer_gui()
    QObject.connect(self.ui.source_layer_cb, SIGNAL("currentIndexChanged(QString)"), self.update)
    QObject.connect(self.ui.dest_layer_cb, SIGNAL("currentIndexChanged(QString)"), self.update)
    self.success = False

def manageGui(self):
    myList = []
    myList = self.getLayerNames( "all" )
    self.ui.source_layer_cb.addItems( myList )
    self.ui.dest_layer_cb.addItems( myList )

def getLayerNames(self, vTypes ):
    layermap = QgsMapLayerRegistry.instance().mapLayers()
    layerlist = []
    if vTypes == "all":
        for name, layer in layermap.iteritems():
            layerlist.append( unicode( ) )
        for name, layer in layermap.iteritems():
            if layer.type() == QgsMapLayer.VectorLayer:
                if layer.geometryType() in vTypes:
                    layerlist.append( unicode( ) )
    return layerlist
share|improve this question
ad 2: Please use stackoverflow for purely programming questions such as this. Also, you should use a default Qt dialog which will automatically provide this behavior. – underdark Nov 13 '12 at 19:05
ad 1: Please provide source code – underdark Nov 13 '12 at 19:09
Underdark, I reworded my question. – GreyHippo Nov 21 '12 at 1:21
@GreyHippo I'm having a similar problem--did you ever figure out what was going on? – user25976 Apr 16 '14 at 23:47

Your Answer


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

Browse other questions tagged or ask your own question.