3
votes

I have code similar to the following:

...
id: myComponent
signal updateState()
property variant modelList: []
Repeater {
    model: modelList
    MyButton {
        ...
        Connection {
            target: myComponent
            onUpdateState: {
                ...
            }
        }
    }
}

I assign a value to modelList and then issue myComponent.updateState() to update the MyButton components in the repeater. At this point I get a lot of warnings about non existent properties

It seems like the signal gets passed to the MyButton(s) that doesn't exist anymore (since the repeater will rerun when I change modelList).

Is there a way of avoiding this or should I simply ignore the warnings?

1

1 Answers

4
votes

I had a similar problem when destroying QML components connected to C++ signals. The problem was solved by adding a handler for disconnecting the signals when the components were destroyed. In the dynamically generated components you could try manually connecting the signals, in order to manually disconnect them on destruction. In my case the code looks something like this:

MyComponent {
    Component.onCompleted: signal.connect(callback_function)
    Component.onDestruction: signal.disconnect(callback_function)

    function callback_function() {
        // process signal
    }
}

It might be, there is a better solution not needing manually connecting and disconnecting the signals, but this worked for me. If you add a console.log("Destroying...") to the onDestruction handler you can check whether or not the components are disconnecting the signal, thus actually being destroyed.