[SOLVED] NumberAnimation on <property alias> doesn't work.



  • I'm trying to animate an aliased property:

    @
    property alias blah: cloudRotation.angle; // assume this line is correct;

        NumberAnimation on blah {
            id: cloudRotationAnimation;
            to: 0;
            duration: 10000;
            loops: Animation.Infinite;
        }
    

    @

    It complains that

    @
    Cannot assign to non-existent property "blah"
    NumberAnimation on blah {
    @

    But if I try it on a normal property, it works fine:

    @
    NumberAnimation on x {
    id: cloudRotationAnimation;
    to: 0;
    duration: 10000;
    loops: Animation.Infinite;
    }
    @

    Can property aliases be used like that? If not, how can I get around it?



  • You can do on alias. Alias will be ready only when the component is completely initialized. If you put the animation directly, it is not completely ready. Check the following piece of code.

    @ Rectangle {
    id : rec
    width: 100; height: 100
    color: "red"

        property alias b : rec.x
        PropertyAnimation { id: animation;target: rec; property: "b"; to: 30; duration: 500 }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                  console.log("I am here")
                  animation.running = true;
            }
        }
    }
    

    @



  • Sweet. That's good to know. Thanks Dheerendra. Is there an onLoad event I could use or something? If so, how'd that work?

    EDIT 11 min later:
    Nevermind, I found Component.onCompleted.



  • Here's my code:
    @
    import QtQuick 2.0;
    import Qt3D 2.0;
    import Qt3D.Shapes 2.0;

    Viewport {
    width: 480; height: 640;

    Sphere {
        radius: 1.5;
        levelOfDetail: 6;
        axis: Qt.YAxis;
        effect: Effect {
            texture: "qrc:/img/earth_day.jpg";
        }
    }
    Sphere {
        radius: 1.535;
        levelOfDetail: 6;
        axis: Qt.YAxis;
        effect: Effect {
            blending: true;
            color: Qt.rgba(255,255,255,0.6);
            texture: "qrc:/img/earth_clouds.jpg";
        }
        transform: Rotation3D {
            id: cloudRotation;
            angle: 0;
            axis: Qt.vector3d(0, 1, 0);
        }
        property alias blah: cloudRotation.angle;
    
        NumberAnimation {
            id: cloudRotationAnimation;
            running: false;
            target: parent;
            property: "blah";
            //from: 0;
            to: 360;
            duration: 10000;
            loops: Animation.Infinite;
        }
        Component.onCompleted: {
            cloudRotationAnimation.running = true;
            console.log("i am here"); // this works
        }
    }
    

    }
    @

    Basically what I'm trying to do is rotate the clouds. When I do
    @
    cloudRotationAnimation.running = true;
    @
    nothing happens. Why might that be?

    EDIT 20 min later:
    Fixed it! I had to change
    @
    cloudRotationAnimation.running = true;
    @
    to
    @
    cloudRotationAnimation.start();
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.