-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
If we have QT_LOGGING_RULES="qt.qml.object.connect.info=true;" then the following code produces a runtime message:
qt.qml.object.connect: Could not find receiver of the connection, using sender as receiver. Disconnect explicitly (or delete the sender) to make sure the connection is removed.
QObject::connect() avoids this scenario by allowing the user to specify a "context object": https://doc.qt.io/qt-6/qobject.html#connect-5 It would be nice if the JS connect allowed the same.
In addition, the contextless version of connect() should then be discouraged by qmllint, like what clazy does: https://github.com/KDE/clazy/blob/master/docs/checks/README-connect-3arg-lambda.md
Code
import QtQuick Window { id: root width: 640 height: 480 visible: true Component { id: comp QtObject { signal finished() function doStuff() { // ... finished() } } } Component.onCompleted: { let obj = comp.createObject(root) obj.finished.connect(function() { console.log("Stuff done!") }) obj.doStuff() } }