Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Animation.onFinished not firing



  • I've got a project in which I am fooling around with various animations and transitions for the fun of it. However, I am not happy to find that Animation.onFinished is not firing as I would think it should. My code is in two files: main.qml:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    
    Window {
        id: windowRoot
    
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        function showMainPage() {
            loader.sourceComponent = mainPage
        }
    
        Loader {
            id: loader
    
            anchors.fill: parent
            sourceComponent: loadingPage
        }
    
        Component {
            id: mainPage
    
            Rectangle {
                color: "lightsteelblue"
            }
        }
    
        Component {
            id: loadingPage
    
            Rectangle {
                anchors.fill: parent
    
                LoadingPage {
                    anchors.centerIn: parent
                }
            }
        }
    }
    

    ...and LoadingPage.qml:

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    
    ProgressBar {
        id: pb
    
        states: State {
            name: "go"
    
            PropertyChanges {
                target: pb
                value: pb.to
            }
        }
    
        transitions: [
            Transition {
                reversible: true
    
                SequentialAnimation {
                    PauseAnimation {
                        duration: 500
                    }
    
                    NumberAnimation {
                        target: pb
                        properties: "value"
                        duration: 1000
                        easing.type: Easing.InOutQuad
                        alwaysRunToEnd: true
                    }
    
                    PauseAnimation {
                        duration: 500
                        onFinished: windowRoot.showMainPage()
                    }
                }
            }
        ]
    
        Label {
            text: qsTr("Loading...")
            anchors.bottom: pb.top
            anchors.horizontalCenter: pb.horizontalCenter
            anchors.margins: 5
        }
    
        Component.onCompleted: pb.state = "go"
    }
    

    For some reason, the second PauseAnimation does not actually fire the onFinished signal. I've also tried with onFinished as part of the NumberAnimation, with the same results.

    I'm using Qt 5.12.8 from the Ubuntu 20.04 repos, and I've also tried 5.15.1 and 6.0.0 without any success.



  • You might to try

    ScriptAction {
      script: doSomething()
    }
    

    after that PauseAnimation



  • You might to try

    ScriptAction {
      script: doSomething()
    }
    

    after that PauseAnimation



  • https://doc.qt.io/qt-6/qml-qtquick-animation.html#finished-signal says:

    In addition, it is only emitted for top-level, standalone animations. It will not be emitted for animations in a Behavior or Transition, or animations that are part of an animation group.



  • @SeeLook thanks, that did the trick.

    @jeremy_k oops, not sure why I didn't see that.


Log in to reply