[SOLVED] Dynamically add element to a model (using javascript) made with C++ backend
Hi all,
I’m finding a way to add/remove item from a ListView;
In my C++ file, I’ve created a model using QList<QObject *> and setContextProperty(); all went ok and it works.
My problem now is to add/remove new element from within javascript…I was hoping that a simple
- myListObject.model.append({"nickname":nickname});
was enought, but… a beautiful:
myListObject.model.append’ [undefined] is not a function.
was shown to me even myListObject and model are both valid!!
I’ve thought that happen because QList<QObject*> doesn’t create a real ListModel (with all function like append, insert and so on…)
Is there someone that know how to resolve this?!?
Thank you
Gianni
1 reply
For those who can be interested in that, I’ve resolved, but not in a elegant way!
In myListView I’ve created a qml ListModel attached to ListView and then thru javascript functions they manipulate ListModel.
But important, you cannot pass from within C++ to qml a flat QList<QObject*> because itsn’t supported well, instead you need to pass the QList thru setContextProperty of QDecalarativeContext to use in qml
Bye
You must log in to post a reply. Not a member yet? Register here!
