How is data being passed?

Hi,
I am new to Python and am working my way through the examples in Create GUI Applications

In listing 12, any text entered into a field is mirrored in a label. The lines of code that do the work are I believe:

                self.label = QLabel()

		self.input = QLineEdit()
		self.input.textChanged.connect(self.label.setText)

The documentation for QLineEdit states :

This signal is emitted whenever the text changes. The text argument is the new text.

Am I correct in understanding this to mean that when the text is changed the signal is fired and the new text is returned and looking at the last line above the .connect portion is calling the setText method of the label. If so then how is the “new text” being passed?

Is it a general rule that any values that are returned from a signal that is being connected with a slot just pass parameters automatically?

best wishes
Simon

I think the last line could be:

self.input.textChanged.connect(self.label.setText(self.input.text())

You need a lambda in this case:

self.input.textChanged.connect(lambda txt: self.label.setText(txt))

Hello, the signal and slot must be compatible for this to work. In that case, QLineEdit.textChanged has a text parameter, which is passed to the slot setText(text). As long a the type is compatible between these two functions, it will work. See the documentation about signals and slots for more details.

From the doc:
void QLineEdit::textChanged(const QString &text)

void QLabel::setText(const QString &text)