我是 QML 和 QML 信号的新手,我遇到了这个我自己无法解决的愚蠢问题。我正在触发 onTouch
信号并执行两次,产生双重响应使我的应用程序崩溃。
这是我的 QML 代码:
//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 } } }
我有这个
TextField
其 ID 是 textFieldKey
在另一个 QML 中,我包括我上面发布的那个。主要思想很简单,是一个键盘,其中每个键都是上面代码的一个组件,它必须打印在此 TextField
中按下的键的值。 .问题是,正如我所说,信号被调用两次,填充
TextField
每次都有两个字符的值。请帮助我,我不知道我是否以正确的方式使用信号或类似的东西遗漏了一些东西。
谢谢!
最佳答案
我想通了。触摸信号有 4 种不同的状态:
每一个都用一个从 0 到 3 的数字来标识。
当触发触摸信号时,涉及两种状态,向下和向上。您只需要确保使用您想要使用的那个并在 onTouch 信号中捕获它:
if (event.touchType == numberOfTheTouchState){
}
关于qt - QML 信号执行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12603551/