Page 1 of 1

Signals and Slots in ECMAScript

Posted: Fri May 25, 2018 10:06 pm
by andrew
From a QCAD user:
How can I use signals and slots in QCAD scripts, for example to detect if the text in a line edit has changed?

Re: Signals and Slots in ECMAScript

Posted: Fri May 25, 2018 10:07 pm
by andrew
Example:

Code: Select all

var le = new QLineEdit();
...
// call this.validate() on text changes:
le.textChanged.connect(this, "validate");

// call an inline function on text changes:
le.textChanged.connect(this, function(text) { qDebug("text is now: " + text); });
See also:
http://doc.qt.io/archives/qt-4.8/scripting.html

Re: Signals and Slots in ECMAScript

Posted: Sat May 26, 2018 4:36 pm
by RR88
How can I detect the sender? Object.sender() does not exist.

Re: Signals and Slots in ECMAScript

Posted: Tue Jun 05, 2018 1:48 pm
by andrew
RR88 wrote:
Sat May 26, 2018 4:36 pm
How can I detect the sender?
I don't think that's available in scripts. Usually a slot is not (and probably shouldn't have to be) interested in the sender.