Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ListModel default property problem
Forum Updated to NodeBB v4.3 + New Features

ListModel default property problem

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    duncanc4
    wrote on last edited by
    #1

    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"
        }
    }
    

    }
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      duncanc4
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BlueMagma
        wrote on last edited by
        #3

        I met the same issue.

        Did you find a way to do it ?

        p3c0P 1 Reply Last reply
        0
        • B BlueMagma

          I met the same issue.

          Did you find a way to do it ?

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by p3c0
          #4

          @BlueMagma Use append instead:

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

          157

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved