【发布时间】:2020-10-07 12:54:15
【问题描述】:
我是 Qt QML 的新手。我正在使用 JS 动态创建 numberAnimation 但收到绑定循环警告。
qrc:/main.qml:18:9:QML 项目:检测到属性“anime”的绑定循环
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
id : global
width: 550
height: 550
visible: true
title: qsTr("Hello World")
Rectangle{
id : exp
x : 0
y : 0
color : "red"
width : 50 ; height : 50
property var anime : createAnimation(exp);
function createAnimation(parent){
let numAnime = Qt.createQmlObject("import QtQuick 2.12; NumberAnimation { onStopped:{to = Math.random()*500; restart() }}", parent)
numAnime.duration = 500
numAnime.easing.type = Easing.OutInSine
numAnime.target = parent
numAnime.property = "x"
numAnime.running = true
return numAnime
}
}
}
另外,有没有办法在 createAnimation(args) 函数中定义 onStopped body?
【问题讨论】: