I'm new in QML and QML signals and I'm having this silly problem that I'm not being able to resolve by myself. I'm triggering an onTouch
signal and is executing twice, generating a double response that crashes my app.
Here's my QML code:
//LabelKey.qml
import bb.cascades 1.0 Container { property string labelText: "#" property real width: 153.3 property real height: 102.5 property int labelPosX: 60 property int labelPosY: 25 property int labelTextFontWidth: 45 property string imgSrc: "asset:///images/keyboard_button.png" layout: AbsoluteLayout { } preferredWidth: width preferredHeight: height objectName: "contTecla" id: contTecla ImageView { objectName: "imgTecla" id: imgTecla1 imageSource: imgSrc preferredWidth: width preferredHeight: height onTouch: { textFieldKey.text = textFieldKey.text + labelTecla.text; } } Label { objectName: "labelTecla" id: labelTecla text: labelText textStyle { color: Color.DarkYellow size: labelTextFontWidth } layoutProperties: AbsoluteLayoutProperties { positionX: labelPosX positionY: labelPosY } } }
I have this TextField
whose id is textFieldKey
in another QML where I'm including the one I post above. The main idea is simple, is a keyboard where each key is a component of the code above and it has to print the value of the key pressed in this TextField
.
The problem is, as I said, the signals is being called twice, filling the TextField
with two chars of the value each time.
Please help me I don't know if maybe I'm missing something in the proper way of using signals or something like that.
Thanks!
I figure it out. The touch signals has 4 differents states:
Down: Occurs when the user touches the screen.
Move: Occurs when the user moves a finger on the screen.
Up: Occurs when the user releases a finger.
Cancel: Occurs when an interaction is canceled.
Each one identify with a number from 0 to 3.
And when a touch signal is triggered two states are involved, Down and Up. You just need to make sure with wich one you want to work with and catch it inside the onTouch signal:
if (event.touchType == numberOfTheTouchState){
}