Odd behavior in a QGIS plugin: my function is triggered twice
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).
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.