ListView model binding to QAbstractListModel derived model
I have following QML ButtonMenu element:
- Rectangle {
- id: menuRoot
- ...
- property Component model
- ...
- Rectangle {
- id: menu
- ...
- ListView {
- id: menuList
- ...
- model: menuRoot.model;
- ...
I use it like this:
- ButtonMenu {
- id: buttonMenu
- ...
- model: menuMainViewArea
- ...
In C++ code I initiate model:
- ctxt->setContextProperty("menuMainViewArea",engine.getMenuMainViewArea());
When I run my program i get following error:
Error: Cannot assign QObject* to QDeclarativeComponent*
I tried to make model in menuRoot an alias to menuList model but when I called model.count when setting size of ButtonMenu I got model.count undefined.
Does anyone know what can be wrong??
7 replies
Using alias works and data from my model is visible in ListView.
However my problem was a little bit different and it was caused by something else.
My menu model changes its content depending from application state. In QML I have used
model.get(i).name and model.count to set appropriate size of my menu. My model from C++ doesn’t have count property and get() function. I thought that they are added (like for normal QML model) somehow by framework, but they are not.
I think that the most reasonable solution is to use ListModel and States in QML.
Thanks for your help :)
You must log in to post a reply. Not a member yet? Register here!

