Search code examples
qtqmlshapesqqmllistproperty

QML ShapePath clear path elements


I want to remove all path elements from my ShapePath. Since pathElements is a Qml list, the only way to modify it is by setting it to a new Javascript array. Therefore, I expected to be able to clear it by just assigning an empty array to it.

I tried path.pathElements = [], which does not work for me.

Then I tried path.pathElements = null, which does work (PathLine is no longer drawn), but it prints this ugly error message: QObject::connect: Cannot connect (nullptr)::changed() to QQuickShapePath::processPath()

Any other ideas?

Code to reproduce:

Shape {
    anchors.fill: parent

    ShapePath {
        id: path

        strokeWidth: 2
        strokeColor: "green"
        fillColor: "green"

        Component.onCompleted: path.pathElements = []

        PathLine { x: 50; y: 50 }
    }
}

Solution

  • I filed a bug report at Qt and they confirmed my bug.

    The workaround until this gets fixed is to first assign null, followed by [].

    Shape {
        anchors.fill: parent
    
        ShapePath {
            id: path
    
            strokeWidth: 2
            strokeColor: "green"
            fillColor: "green"
    
            Component.onCompleted: {
                path.pathElements = null
                path.pathElements = []
            }
    
            PathLine { x: 50; y: 50 }
        }
    }