首页| 论坛| 消息

标题:QML Rectangle: Binding loop detected for property "y" 该如何解决?
作者:oceanljp
日期:2011-07-28 18:04
内容:

直接上代码:import QtQuick 1.0
Item {
Rectangle {
id: buttonRect
width: 96
height: 96
color:"black"
Image {
id: img
source: "./tux.png"
anchors.centerIn:parent
}
MouseArea {
id:mouseArea
anchors.fill: parent
}
states: State {
name: "down"; when: mouseArea.pressed == true
PropertyChanges { target:buttonRect ; y: y + 3 ; x : x + 3; }
}
}
}上面代码目标实现一个按钮的功能。当点击按钮时,按钮会向右向下移动3像素,以模拟被按下的情况。目前程序运行正常,但是在按下按钮时,会打印如下警告:
QML Rectangle: Binding loop detected for property "y"
QML Rectangle: Binding loop detected for property "x"
求能消除这些警告的方法。
不考虑重定向错误输出,禁止waring的解决方法。


#1 回 楼主(oceanljp) 的帖子 [wxj120bw 07-29 21:37]
楼主看下 http://permalink.gmane.org/gmane.comp.lib.qt.qml/1622 就能解决你的问题
#2 [oceanljp 07-30 09:48]
楼上的连接给出了线索,不过具体解决办法要在官方文档中找。
相关连接如下:
http://doc.qt.nokia.com/4.7/qml-propertychanges.html

具体到代码中,就是将如下代码
PropertyChanges { target:buttonRect ; y: y + 3 ; x : x + 3; }改为:
PropertyChanges { target:buttonRect ; explicit : true ; y: y + 3 ; x : x + 3; }多谢楼上指点啊。
#3 回 2楼(oceanljp) 的帖子 [wxj120bw 07-31 09:57]
先前我也解决了警告问题,不过代码比你上面多了许多。我先得到鼠标点击之前buttonRect的坐标,然后在点击时赋给。这样就没有绑定的警告了。
Item {
Rectangle {
id: buttonRect
width: 96
height: 96
color:"black"
property int curX: 0
property int curY: 0
Image {
id: img
source: "states.png"
anchors.centerIn:parent
}
MouseArea {
id:mouseArea
anchors.fill:parent
hoverEnabled: true
onEntered: {
curX:buttonRect.x;
curY:buttonRect.y;
}
}
states: [
State {
name:"down"
&nb ..
#4 [oceanljp 08-02 17:57]
呵呵,条条大路通罗马。

回复 发表
主题 版块