[Unsolved] Connecting a signal to a function in an identical item
-
I've been trying to solve this for a while now but no luck, I can't find anything wrong with the code. It's time for me to ask for help, so this is what I am wanting to accomplish:
I have made an item called SwitchComp, which is basically a switch that has the states on and off. The function called "receive" handles the simple logic to switch the state to the opposite (if it's on, it switches to off, and if off, on.) Then there is an item (Switch) that contains two of these components, that will send a signal to eachother called switchTo. When this signal is received it will process the logic inside the function that i described, and also the SwitchComp messenger (the SwitchComp that was clicked) will do the same. Basically the Switch is identical to an on off switch of a lamp on the ceiling.
Here is the code
@import QtQuick 2.0Item {
id: newSwitch
width: 40
height: 80SwitchComp { id: onn state: "on" MouseArea { anchors.fill: onn onClicked: { onn.switchTo.connect(off.receive) onn.switchTo } } } SwitchComp { id: off anchors.top: onn.bottom state: "off" MouseArea { anchors.fill: off onClicked: { off.switchTo.connect(onn.receive) off.switchTo } } }
}@
-
I dunno why, but I made a similar program that connect two buttons together that each have a function called "stringReceive" that takes a string parameter, which will change the label of the button to the value in the parameter. I interconnected a sendString signal to each of the buttons that will be triggered once you click one of them and activate the function in the button it is connected to.
It basically works just as my previous program, but this one actually did what it was supposed to do.