Well, 5 minutes after my question, I made a workaround: connect only once to one signal, which causes jsobject from the inside:
Item { property var fire // Any qml object. In this example it is ActionExecutor which emits actionRequest ActionExecutor { //signal actionRequest(int actionType) onActionRequest: fire(actionType) } Action { shortcut: "Ctrl+S" text: "One action" onTriggered: { parent.fire = function(actionType) { console.log('one slot') } } } Action { shortcut: "Ctrl+X" text: "Another action" onTriggered: { parent.fire = function(actionType) { console.log('Another slot') } } } }
So that the js object can be reassigned as many times as you want, you can change your behavior by reassigning this object. If you want to disable all simple assignments undefined to fire . You can also create a chain of " slots " by changing the code to something like:
Item { property var fire property var slots: [ function(actionType) { console.log('1: ' + actionType) }, function() { console.log('2: ' + actionType) }, function() { console.log('3: ' + actionType) } ] // Any qml object. In this example it is ActionExecutor which emits actionRequest ActionExecutor { //signal actionRequest(int actionType) onActionRequest: fire(actionType) } Action { shortcut: "Ctrl+S" text: "One action" onTriggered: { parent.fire = function(actionType) { console.log('calling all custom JS-slots') for (var i in slots) { slots[i](actionType) } } } } }
Thus, everyone can implement their own signal slot architecture in qml as a simple javascript observer template. Enjoy it.
source share