Qt NumberAnimation属性绑定循环问题
我是Qt-QML的新手。我正在使用JS动态创建一个numberAnimation,但得到绑定循环警告 qrc:/main.qml:18:9:qml项:检测到属性“anime”的绑定循环Qt NumberAnimation属性绑定循环问题,qt,qml,Qt,Qml,我是Qt-QML的新手。我正在使用JS动态创建一个numberAnimation,但得到绑定循环警告 qrc:/main.qml:18:9:qml项:检测到属性“anime”的绑定循环 另外,是否有方法在createAnimation(args)函数中定义onStopped body?您可以通过在组件中指定动画上的绑定来移除该绑定。onCompleted。是的,您可以通过将createAnimation连接到函数,在createAnimation的主体中定义onStopped,如下所示:
另外,是否有方法在createAnimation(args)函数中定义onStopped body?您可以通过在
组件中指定动画
上的绑定来移除该绑定。onCompleted
。是的,您可以通过将createAnimation
连接到函数,在createAnimation
的主体中定义onStopped
,如下所示:
Rectangle{
id : exp
x : 0
y : 0
color : "red"
width : 50 ; height : 50
property var anime
Component.onCompleted: anime = createAnimation(exp);
function createAnimation(parent){
let numAnime = Qt.createQmlObject("import QtQuick 2.12; NumberAnimation {}", parent)
numAnime.duration = 500
numAnime.easing.type = Easing.OutInSine
numAnime.target = parent
numAnime.property = "x"
numAnime.running = true
numAnime.onStopped.connect(function() { numAnime.to = Math.random() * 500; numAnime.restart() })
return numAnime
}
}
这正是我要找的。但是你能解释一下为什么会有绑定循环吗?我不确定原因,不。
Rectangle{
id : exp
x : 0
y : 0
color : "red"
width : 50 ; height : 50
property var anime
Component.onCompleted: anime = createAnimation(exp);
function createAnimation(parent){
let numAnime = Qt.createQmlObject("import QtQuick 2.12; NumberAnimation {}", parent)
numAnime.duration = 500
numAnime.easing.type = Easing.OutInSine
numAnime.target = parent
numAnime.property = "x"
numAnime.running = true
numAnime.onStopped.connect(function() { numAnime.to = Math.random() * 500; numAnime.restart() })
return numAnime
}
}