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

How to use var properties for lists of elements?



  • Can you help me to figure out correct way to use lists in custom QML properties?
    Here is example:

    --- Elem.qml
    @import QtQuick 2.0

    QtObject {
    property string name
    }@

    --- Cont.qml
    @import QtQuick 2.0

    QtObject {
    property var elements
    }
    @

    --- main.qml
    @import QtQuick 2.2

    Rectangle {
    Cont {
    elements: [
    Elem { name: "1" },
    Elem { name: "2" }
    ]
    }
    }@

    Running this using qmlscene from Qt-5.2 produces following error:
    @Starting /opt/qt-5.2.1/5.2.1/gcc_64/bin/qmlscene...
    file:///home/usov/build/qml/main.qml:6 Cannot assign multiple values to a singular property

    /opt/qt-5.2.1/5.2.1/gcc_64/bin/qmlscene exited with code 255@

    As far as I understand, this means that last paragraph of "this QML manual page":http://qt-project.org/doc/qt-5/qml-list.html is wrong.


Log in to reply