How to fix "Duplicate method name: invalid override of property change signal or superclass signal"?

Viewed 612

On Qt 5.15.1 I want to connect to the objectNameChanged signal of a QML Item using Connections:

import QtQuick 2.15
import QtQuick.Window 2.15

Window {
    visible: true

    Item {
        id: foo
    }

    Connections {
        target: foo

//      onObjectNameChanged: console.log(foo.objectName) // old syntax, causes "Implicitly defined onFoo properties in Connections are deprecated."
        function onObjectNameChanged() {
            console.log(foo.objectName)
        }
    }
}

The code produces the following error:

Duplicate method name: invalid override of property change signal or superclass signal

I can of course write it like this:

Item {
    id: foo

    onObjectNameChanged: console.log(foo.objectName)
}

but I need to use Connections.

How to fix this?

1 Answers

From my comment:

The cause of the error is easy to explain: Connections is also a QObject so it also has the objectName property (and the associated signal) and when mapping the objectName property of the target it generates the problem, I don't think there is a workaround so that I recommend you report the bug.

Related