I am having some trouble passing arguments to a function using functools.partial()
when connecting it to a GUI Qt signal (log_this() is a dummy function just to convey the problem):
self.ui.comboBox_1.currentIndexChanged.connect(functools.partial(self.log_this, val='aaaaaa'))
def log_this(self, val='0000'):
log.info(val)
gotten error:
TypeError: log_this() got multiple values for argument 'val'
if I use lambda to call the function it works fine:
self.ui.comboBox_1.currentIndexChanged.connect(lambda: self.log_this(val='aaaaaa'))
looking into this, I see that log_this()
is getting the current comboBox index. I also tried working with positional arguments and also gotten an error like the above.
I want to understand if it is correct to use functools.partial() or should I just stick to lambda on such cases. if correct, what is the right way to do it?
Adding more details:
my class:
class AppMainWindow(QtGui.QMainWindow):
message = QtCore.Signal(str)
def __init__(self, parent=None):
super().__init__(parent=parent)
self.manual_test = True
self.all_tests_enabled = False
self.set_connections()
def set_connections(self):
self.ui.comboBox_1.currentIndexChanged.connect(
functools.partial(self.log_this, val='aaaaaa'))
self.ui.pushButton_1.clicked.connect(self.add_item)
def log_this(self, val='0000'):
log.info(val)
I am using PySide 1.2.2.
Thanks in advance!