Search code examples
qtqmlparentqtquick2

QML: NumberAnimation can't refer to its parent SequentalAnimation


My code:

import QtQuick 2.5
import QtQuick.Window 2.2

Window {
    visible: true
    width: 640
    height: 480
    property double angle: 0

    SequentialAnimation on angle {
        property int myDuration: 3000 // const
        NumberAnimation {
            from: -30.0
            to: 30.0
            duration: parent.myDuration
            easing.type: Easing.InOutSine
        }
    }
}

I get this error on the "parent.myDuration" line:

ReferenceError: parent is not defined

Any ideas?


Solution

  • parent is a property of Item, an Animation is not a visual item, it inherits from QtObject.

    There is no property in Animation to refer to its parent animation group. What you could do is setting an id to your SequentialAnimation and refer to this id in your NumberAnimation