QML signal is executed twice

I am new to QML and QML signals, and I have this stupid problem that I cannot solve on my own. I fire the onTouch signal and execute it twice, generating a doble response that breaks my application.

Here is 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, where id is textFieldKey in another QML, where I include the one I post above. The basic idea is simple, it is a keyboard, where each key is a component of the above code and should print the value of the key pressed in this text box.

The problem is that, as I said, the signals are called twice, each time filling the text field with two characters of the value.

, , , , - , - .

!

+5
2

. 4 :

: , .

: , .

: , .

: .

0 3.

, : . , , onTouch:

if (event.touchType == numberOfTheTouchState) { }

+2

ImageView
{
    objectName: "imgTecla"
    id: imgTecla1
    imageSource: imgSrc
    preferredWidth: width
    preferredHeight: height
    onTouch:
    {
        if(event.isDown())
        {
            textFieldKey.text = textFieldKey.text + labelTecla.text;
        }
    }
}

As noted, without this you get both up and down events

0
source

All Articles