Important: Please read the Qt Code of Conduct -

QML Component event order

  • I'm reasonably new to QML and always learning, I have inherited a large project with a lot of badly written QML with a lot of JavaScript and calls to routines in the C++ application.

    Much of this hasn't been written using any sensible software development guide lines and there are multiple ways of achieving the same thing which isn't good.

    I would like to explore if I can improve this and make it more deterministic. I have read and can see that some of the QML uses Component.onCompleted, not in many cases.

    I could like to see if I can use these when a page is loaded to set-up the QML using the C++ calls that I have available. Also is the onDestruction event called when the QML is changed to another?

    I've been experimenting with Component, I added this to one of the pages:

        Component.onCompleted: {
            console.log("******** HACK my.qml onCompleted L###");
        Component.onDestroyed: {
            console.log("******** HACK my.qml onDestroyed L###");

    I can see that when the page is loaded I get the onCompleted message in the Application Output, but I don't see the onDestroyed if I change the page, only when the application is terminated. Is there any way to pick up when the page changes?

    I tried adding:

        Component.onStatusChanged: {
            console.log("******** HACK my.qml onStatusChanged L###: " + status);

    But this resulted in the application crashing with a critical error handler on launch, removing it solved the problem.

Log in to reply