I am creating a QGIS plugin. I have added a combo box and a push button in the plugin. The issue that I am facing is that I want the ComboBox to either allow selection of layers from the layers loaded on the project or when the user clicks the pushButton it should navigate to the directory and the ComboBox should be filled with the layer selected from the pushButton. Both work individually, but I can't seem to get them working together. I am a beginner in Python, so please let me know if there is anything very obvious that I have missed out on. I am giving my code below. When I run it I get the error -

TypeError: native Qt signal is not callable

def select_input_raster(self):
  filename, _filter = QFileDialog.getOpenFileName(
    self.dlg, "Select input raster ","", '*.tif')

def run(self):

    if self.first_start == True:
        self.first_start = False
        self.dlg = ComboBoxPushButtonDialog()

    layerlist1 = ['<Select a raster layer>']
    layers1 = QgsProject.instance().mapLayers().values()
    for layer in layers1:
        if layer.type() == QgsMapLayer.RasterLayer:

        #else layerlist1.append(select_input_raster())

    #Clear the contents of the comboBox from previous runs
    # Populate the comboBox with names of all the loaded raster layers
    # show the dialog
    # Run the dialog event loop
    result = self.dlg.exec_()
  • Does it mention what line the error is originating from? – Joseph Jun 25 '19 at 10:20
  • 2
    The fourth line - self.dlg.comboBox.currentTextChanged(filename) – E_123 Jun 25 '19 at 10:25

currentTextChanged() is a signal which needs to be connected to a function. I.e.


I think what you want is something like:

def select_input_raster(self):
    filename, _filter = QFileDialog.getOpenFileName(
      self.dlg, "Select input raster ","", '*.tif')
    # Add the selected filename to combobox
    # Obtain index of newly-added item
    index = self.dlg.comboBox.findText(filename)
    # Set the combobox to select the new item
  • 1
    Thank you. This worked. Now I am getting a better understanding. – E_123 Jul 1 '19 at 6:48
  • @B_123 - Most welcome, glad it helped :) – Joseph Jul 1 '19 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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