Consider the following PySide2 program (python version 3.8.6 and PySide2 version 5.15.1):
from PySide2.QtWidgets import QApplication, QLineEdit
def setup(w, sigs):
for name, f in sigs:
getattr(w, name).connect(lambda *args: f(*args))
app = QApplication()
win = QLineEdit()
setup(win, [("textChanged", lambda *args: print(" text", args)),
("returnPressed", lambda *args: print("return", args))])
win.show()
app.exec_()
And this is the output when I type "asdf" and press ENTER:
return ('a',)
return ('as',)
return ('asd',)
return ('asdf',)
return ()
I would expect this to be
text ('a',)
text ('as',)
text ('asd',)
text ('asdf',)
return ()
Why is PySide connecting the later callback function on the QLineEdit? If I change the setup
function to
def setup(w, sigs):
for name, f in sigs:
getattr(w, name).connect(f)
It works as expected. The following also works:
def const(f):
return lambda *args: f(*args)
def setup(w, sigs):
for name, f in sigs:
getattr(w, name).connect(const(f))