I am developing a plugin for the GIS software, QGIS. I have a QAction icon which, when checked, connects layers in a group to a function whenever their visibility is toggled. Then when it is unchecked, it is supposed to disconnect these functions but instead I receive an error:
Traceback (most recent call last):
File "C:/Users/Me/.qgis2/python/plugins\Example\Example.py", line 248, in run
layers.visibilityChanged.disconnect(print_one)
TypeError: 'function' object is not connected
This is an example code:
def run(self, checked):
root = QgsProject.instance().layerTreeRoot()
group = root.findGroup('Group')
def print_one():
print 'one'
if checked == True:
for layers in group.children():
layers.visibilityChanged.connect(print_one)
else:
for layers in group.children():
layers.visibilityChanged.disconnect(print_one)
Why is the signal not being disconnected?
I could just use layers.visibilityChanged.disconnect()
but this disconnects all signals to it so is not in my interest.