List View using two elements
Hello everyone, I’d like to ask few things about the list view. I’d like to make a list view similar with the last example (list view section)at http://doc.qt.nokia.com/4.7-snapshot/qml-views.html
The problem is that my data will not be coming raw out of the box, instead i’d like to take it from a function, my question is, how do i insert a parametrized function as the name in the name?
This is my modification of the code:
- ListModel {
- id: myModel
- ListElement { ListElement.objectName: memberSelectionCpp.fungsiReturnID(2); team: 1 }
- ListElement { name: "Bob"; team: 2 }
- ListElement { name: "Jane"; team: 3 }
- }
how can i have the list element name derived from a function in cpp? i have registered the function as memberSelectionCpp.fungsiReturnID and the (2) is supposed to be the index.
Thanks for helping.
12 replies
oops, i missed some details..
i used the setContextProperty, this is the code:
- view->engine()->rootContext()->setContextProperty("memberSelectionCpp",selectLevel);
And the seen member of team 1 is “undefined”
the fungsiReturnID is as follows:
- {
- return soapResult.result->__ptr[index]->UserID;
- }
i used a gsoap to return ID from my dummy database
it is possible to display the data if i inputted it manually, but just in case if my data got increasing, then it would get even harder to input them all manually, right? Any suggestion to fix it? Thanks.
i tried using that trick as well, but instead it gives a warning “ListElement: cannot use script for property value ListElement { name: memberSelectionCpp.fungsiReturnID(2) ; team: 1 }”
And when i try to type ListElement, the autocomplete shows only two options: deleteLater or objectName, so i picked the objectName, and the result is undefined. Could it be that i used the wrong syntax?
I think, with ListElement.objectName, you are trying to assign value to “objectName” property of the ListElement.
For back-ground about objectname, http://doc.qt.nokia.com/latest/qobject.html#objectName-prop
i’m sorry, but could anyone explain more? My problem is that i can not insert strings that is being returned by a function in cpp into list view element. I have tried to look for sample codes but all that i found is the list view name that is inputted manually, and since i have quite some data, i don’t think that it will be possible,, Help, anyone?
thank you
Looks like some good news for you.. You can do it..
- ListModel {
- id: myModel
- ListElement { name: "Bob"; team: 2 }
- ListElement { name: "Jane"; team: 3 }
- Component.onCompleted: {
- append({name:memberSelectionCpp.fungsiReturnID(2),team:1})
- }
- }
If you want to insert your element in a different place, you can use insert function of ListModel.
But you need to make sure something from C++ side..
Make sure that “memberSelectionCpp” is made available to qml with setContextProperty before you set your qml file to QDeclarativeView. Otherwise above code does not work. Try and let us know if this works.
You must log in to post a reply. Not a member yet? Register here!



