ListModel and onChanged signals
-
Has the ListModel element a special behavior on properties? I have this in a separate QML-File (OauthJsonListModel.qml):
@ListModel {
id: oauthJsonListModelproperty 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? -
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.
-
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)
-
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.