Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    ListModel and onChanged signals

    QML and Qt Quick
    3
    4
    3147
    Loading More Posts
    • 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.
    • M
      MrBlueSky125 last edited by

      Has the ListModel element a special behavior on properties? I have this in a separate QML-File (OauthJsonListModel.qml):

      @ListModel {
      id: oauthJsonListModel

      property string source
      property string query: "payload"
      property bool oauthEnabled: token != "" && secret != ""
      property string token
      property string secret
      property string status: ""
      property string json
      
      signal oauthFailed
      signal requestError
      
      onSourceChanged: console.log("Bluub");
      

      }@

      But i get always this error:
      @ListModel: undefined property 'onSourceChanged'
      onSourceChanged: console.log("Bluub"); @

      When I remove the onSourceChanged handler, all works fine.
      It's strange. Did I miss something?

      1 Reply Last reply Reply Quote 0
      • C
        chriadam last edited by

        ListModel and ListElement are special. They are parsed with a custom parser, and certain things which are supported for other object types are not supported for those types. It may be that automatic property-notifier and signal-handler generation, is one of those things. I'll confirm and reply to this thread when I find out for sure.

        1 Reply Last reply Reply Quote 0
        • Z
          z.emb last edited by

          Thanks for the update so far. I assumed that there is something 'special' about ListModel.

          Is there any other basic QML type I can use for a model (which means I can assign it directly to a view)? I created a XML model equivalent, but for json files and included OAuth authentification and want to use it like the xml model.

          Of course, I could write a C++ class and do there all the fancy stuff, but I wanted to do this in pure qml/js, because it is .. JSON :-)

          Thanks again.

          Edit: (oops, logged in with the wrong account)

          1 Reply Last reply Reply Quote 0
          • C
            chriadam last edited by

            Just confirming that the warning you see is coming from the custom parser for ListModel elements. It seems that change signals aren't supported for that type.

            Regarding the model, you can still use a ListModel, but maybe use an intermediate Item element which has the various properties, and in the change signal handlers, set the appropriate source etc on the ListModel.

            Other things which can be used as a model for a view are listed in the docs at http://doc-snapshot.qt-project.org/5.0/qtquick-modelview.html (including object instances, etc).

            Cheers,
            Chris.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post