Connections with two targets?
-
I wonder if it's possible to bind two signals from two objects to one slot in
Connections
. If not, is that worth a bug report/feature request?I can use a function call, but it's just my curiosity.
-
Yes, just connect the signals and slots one by one as you need.
There is even a class for doing more complicated connection mappings:
http://doc.qt.io/qt-5/qsignalmapper.html -
@tekojo I was talking about QML
Connections
type :) -
Ah, sorry I misunderstood.
But the same answer :)
Connections can be used to connect multiple signals to one slot
http://doc.qt.io/qt-5/qml-qtqml-connections.html#details -
@tekojo Sorry, but I couldn't understand how.
Is it like (This is just an example):
MouseArea { Connections { onClicked, onEntered: foo(parameters) } }
And Do I use:
target: button, textInput
I can make two
Connections
types, but that's not the question. -
AFAIK there is no way to do this in
Connections
. An alternative is to use theconnect
method. -
@SafaAlfulaij Not exactly a solution but try the following:
Item { width: 100 height: 100 QtObject { id: sender signal post (var obj, var data) } Item { id: a objectName: "ItemA" Component.onCompleted: { sender.post(this, "This is from Item A") } } Item { id: b objectName: "ItemB" Component.onCompleted: { sender.post(this, "This is from Item B") } } Connections { target: sender onPost: { console.log(obj, data) console.log(obj.objectName) } } }
In
onPost
you get access to individual objects. -
Is the
Connections
component a singleton or am I missing something again? As far as I can tell it's a regularQObject
, so I think this should work:MouseArea { // ... Connections { target: button onClicked: foo(parameters) } Connections { target: textInput onEntered: foo(parameters) } }
-
@kshegunov that is possible too. But OP is asking for a single Connections objects and which can accept 2 targets.
-
@kshegunov Perhaps OP must have thought of comparing c++ feature