I have assigned one method to combobox like this

def run(self):

    """Run method that performs all the real work"""
    #attach index changed event / passing parametrized method
    self.dlg.cbLayerNamesAll.currentIndexChanged.connect(lambda arg=self:  LayersValueChange(arg))

getting error here

def LayersValueChange(self):
    print "abc"
    #selectedLayerName = str(self.dlg.cbLayerNamesAll.currentText())
    #selectedLayerName = self.dlg.cbLayerNamesAll.currentText()

    layers = self.iface.legendInterface().layers()//here error

And Error is:

layers = self.iface.legendInterface().layers()
AttributeError: 'int' object has no attribute 'iface'

self is object but it getting it like int.

  • Did you use the Plugin Builder to create your plugin? If not, make sure your mainPlugin.py file contains the correct reference to iface as described here. – Joseph Oct 5 '16 at 12:17
  • i guess there problem in registering function on currentIndexChange – Muhammad Faizan Khan Oct 5 '16 at 12:30

I have managed to get the answer through stackoverflow. I connecting method wrongly correct syntax is:

 self.dlg.cbLayerNamesAll.currentIndexChanged.connect(lambda: LayersValueChange(self))
| improve this answer | |

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.