首页 文章

QML信号执行两次

提问于
浏览
6

我有这个愚蠢的问题,我触发 onTouch 信号并执行两次,产生一个双重响应,崩溃我的应用程序 .

这是我的QML代码:

//LabelKey.qml导入bb.cascades 1.0

容器 {

property string labelText:“#”
properties 实际宽度:153.3
properties 实际高度:102.5
property int labelPosX:60
property int labelPosY:25
property int labelTextFontWidth:45
属性字符串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;
}
}
标签 {
objectName:“labelTecla”
id:labelTecla
text:labelText
textStyle {
颜色:Color.DarkYellow
size:labelTextFontWidth
}
layoutProperties:AbsoluteLayoutProperties {
positionX:labelPosX
positionY:labelPosY
}
}
}

我有一个 TextField ,其ID是 textFieldKey 在另一个QML中,我包括我在上面发布的那个 . 主要思路很简单,就是一个键盘,其中每个键都是上面代码的一个组成部分,它必须打印在此 TextField 中按下的键的值 .

问题是,正如我所说,信号被调用两次,每次用两个字符填充 TextField .

请帮助我,我不知道是否可能错过了使用信号或类似信息的正确方法 .

谢谢!

2 回答

  • 0

    我明白了 . 触摸信号有4种不同的状态:

    • 向下:当用户触摸屏幕时发生 .

    • 移动:当用户在屏幕上移动手指时发生 .

    • Up:用户松开手指时发生 .

    • 取消:取消交互时发生 .

    每个人都用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;
            }
        }
    }
    

    如上所述,如果没有这个,您将获得上下事件

相关问题