I have a plugin with a function (triggered by a button) that selects a specific layer by name, then shows its attribute table. When I close the plugin and open it again, the attribute table pops up twice, and repeating this keeps adding another table popup. What's wrong?


def showTable(self):
    for lyrs in QgsMapLayerRegistry.instance().mapLayers().values():
        if lyrs.name() == "TestFeatures":
            lyrTest = lyrs

2 Answers 2


You are probably setting a connection between a SIGNAL (button clicked) and a SLOT (your method showTable) every time your plugin is open (run() method?) and you are not disconnecting such SIGNAL/SLOT when your plugin is closed. This leads to a new call to showTable() every time you open your plugin, because there's a new connection calling it.

A couple of solutions for this problem are to:

  • Disconnect your SIGNAL/SLOT when closing the plugin; or (recommended)
  • Set your connection only in the initGui() method of your plugin, this way a new connection won't be set when opening your plugin, but only when initializing QGIS (or reloading the whole plugin).
  • That was the actual problem - the button connections were done in the run() method. Thanks.
    – MapEngine
    Mar 1, 2015 at 10:15
  • Could you develop a little bit? when placed in iniGui() the button seems inactive" self.dlg = PluginDialog() self.dlg.pushTest.clicked.connect(self.test_function)
    – Leo
    Nov 22, 2019 at 5:05

The problem can be that you have created your dialog with qt designer and there is already defined slot and you have defined it again in your code. Remove button.accepted.connect from your code.

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.