I am having trouble with an error which should not be possible.. Here is my situation :
I am developping a IHM in pyside2, so I am using widgets with signals like buttons.
I want to use a method inside an other method and all this is inside a for loop. So I am using the lambda method. Except this time something strange happen. When I want to call a method of myObject inside the lambda, I have the error int object has no attribute myMethod but the method does exist and myObject is not an int !
This is a simple example of what I am doing :
myOtherObject = myOtherClass()
for i in range(10):
myObject = myClass(i)
myOtherObject.myOtherMethod.connect(lambda obj=myObject: obj.myMethod())
So I investigated this error and when I print the variable obj inside the lambda, it returns to me "0 or 2" everytime I am doing my signal, which is an On/Off button by the way.
- Button clicked On => obj = 2
- Button clicked Off => obj = 0
Any idea ?