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.



  • Hi, can you clarify if memberSelectionCpp is a qml property exposed from C++ with setContextPropery or a C++ class exposed with qmlRegisterType?



  • Could you explain more ? I didn't understand what you want.
    Why is it impossible to get all data and after send them to the listModel ?



  • 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:
    @QString memberSelect::fungsiReturnID(int index)
    {
    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 this and got a run time error that script can not be used to specify ListElement property value. Can "TROLLS" help here?

    @chronoske, are you getting any qml run-time error?



  • nope, i didn't get any run-time error at all, the return string just doesn't show. that's all..



  • @ ListElement { ListElement.objectName: memberSelectionCpp.fungsiReturnID(2); team: 1 }@

    I did not get whey are you using ListElement.objectname here?? where did you get this from?

    Should't it be something like
    @ListElement { name: memberSelectionCpp.fungsiReturnID(2); team: 1 }@

    may be I am wrong...



  • 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.



  • I still can't figured it how, so I guess I'll try to change the concept for my project. Thanks everyone!



  • [quote author="chronoske" date="1310520896"]I still can't figured it how, so I guess I'll try to change the concept for my project. Thanks everyone![/quote]

    It seems to work for me. What is the problem you are facing..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.