Functions get called more and more times with reopening plugin
<p>I have a QGIS plugin written in Python 2.7.3 with PyQt 4.9.1, Qt 4.8.1. When I run this plugin every function works just fine. But when I close the window and reopen it again, every function happens twice. Then I close/open again and it goes 3 times, etc., etc.</p>

<p>Where should I look for an error here? My <code>def run(self)</code> part looks just like this:</p>

<pre><code>def run(self):

    self.dlg.show()

    self.availableLayers()

    self.dlg.pushButton_2.clicked.connect(self.openFile)

    self.dlg.pushButton.clicked.connect(self.groupBy)

    self.dlg.toolButton_4.clicked.connect(self.toggleRightPanel)
</code></pre>

<p>If I reload the plugin by clicking the button from "Plugin Builder", it starts again from one.</p>

<p>I should also mention I wouldn't like to lose the view user created (the plugin is a table viewer), but rather be able to close the window, open it and have it again there without the cells being cleared.</p>

<p>Every time you call <code>connect</code>, it adds another connection - even if it's to the same slot. So you need to move the connections out of the <code>run()</code> method and put them in the setup method for the dialog, so that they are only made once.</p>

python qt pyqt qgis