Define ListElement at an external file



  • hello

    I want define the ListElement in different file and use code like this:

    MyListModel.qml
    @import QtQuick 2.0

    ListModel {
    dynamicRoles: true

    ListElement {
        someitems:[
            SomeItem{},
            SomeItem{},
            SomeItem{},
            SomeItem{}
        ]
    }
    

    }@

    SomeItem.qml
    @import QtQuick 2.0

    ListElement {
    recordID: Math.round(Math.random()*1000)
    eqType: 0
    message: "some text"
    }@

    main.qml
    @import QtQuick 2.0

    Item {
    anchors.fill: parent
    property MyListModel myListModel: MyListModel{}

        ListView {
                width: parent.width
                height: parent.height
    
                model: myListModel.get(0).someitems
                delegate:
                    Rectangle {
                        width: parent.width
                        height: 90
                    }
        }
    

    }@

    i got runtime error at file MyListModel.qml at line 8

    ListElement : cannot contain nested elements

    how resolve it?



  • @
    import QtQuick 2.0

    ListModel {
        dynamicRoles: true
     
        ListElement {
            someitems:[
                ListElement{
                      recordID: Math.round(Math.random()*1000)
                      eqType: 0
                      message: "some text"
                },
                ListElement{
                      recordID: Math.round(Math.random()*1000)
                      eqType: 0
                      message: "some text"
                },
                ListElement{
                      recordID: Math.round(Math.random()*1000)
                      eqType: 0
                      message: "some text"
                }
            ]
        }
    }
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.