ListModel default property problem



  • If I define a ListModel in a separate qml file, then try in to use it in another qml file and add items, I get an error saying: Cannot assign to non-existent default property. Is this a bug, or is this how ListModel is designed to work? I looked over the source for ListModel, but couldn't find anywhere a default property is defined.

    ListModelTest.qml
    @
    import QtQuick 2.1

    ListModel
    {
    }
    @

    Main.qml
    @
    import QtQuick 2.1

    Rectangle
    {
    ...

    ListModelTest
    {
        ListElement
        {
             text: "test"
        }
    }
    

    }
    @



  • Upon further digging through the source for ListModel, I realize that the reason there is no default property for ListModel is because it uses a custom parser.



  • I met the same issue.

    Did you find a way to do it ?


  • Moderators

    @BlueMagma Use append instead:

    ListModelTest  {
       Component.onCompleted: {
             append( { text : "test" } )
      }
    }
    

Log in to reply
 

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