Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

10K Developer Commitment

Reply
New Contributor
mariomunera
Posts: 2
Registered: ‎09-26-2012
My Carrier: Computer Engineer

QML signal executed twice

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 doble response that crash 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 wich 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 dont know if maybe I'm missing something in the proper way of using signals or something like that.

Thanks!

Please use plain text.
New Contributor
mariomunera
Posts: 2
Registered: ‎09-26-2012
My Carrier: Computer Engineer

Re: QML signal executed twice

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){ }

Please use plain text.