I developed a plugin in QGIS and I have attached a function on button clicked but it is calling the function two times and I don't know the reason why.
I am registering click function in plugin run event:
def run(self):
"""Run method that performs all the real work"""
AttachBtnClicked(self)
# show the dialog
self.dlg.show()
# Run the dialog event loop
result = self.dlg.exec_()
def AttachBtnClicked(self):
self.dlg.btnDataSourceEncodingChangeAllLayers.clicked.connect(lambda: btnDataSourceEncodingChangeAllLayersClicked(self))
while the method is:
def btnDataSourceEncodingChangeAllLayersClicked(self):
print 'DataSourceEncodingChanageAllLayers : '# + encodingName
LayerDataSourceChange()
it runs two times.
self.dlg.btnDataSourceEncodingChangeAllLayers.clicked.connect(btnDataSourceEncodingChangeAllLayersClicked)and put it in init method. From run method remove function call. – DIV Dec 01 '16 at 09:24self.dlg.btnDataSourceEncodingChangeAllLayers.clicked.connect(self.btnDataSourceEncodingChangeAllLayersClicked)– DIV Dec 01 '16 at 10:07