June 21, 2011

chronoske chronoske
Lab Rat
31 posts

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:

  1. ListModel {
  2.             id: myModel
  3.             ListElement { ListElement.objectName: memberSelectionCpp.fungsiReturnID(2); team: 1 }
  4.             ListElement { name: "Bob"; team: 2 }
  5.             ListElement { name: "Jane"; team: 3 }
  6.         }

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

June 21, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

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

June 21, 2011

dridk dridk
Lab Rat
48 posts

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 ?

 Signature 

Nothing in Biology Makes Sense Except in the Light of Evolution

June 22, 2011

chronoske chronoske
Lab Rat
31 posts

oops, i missed some details..

i used the setContextProperty, this is the code:

  1. view->engine()->rootContext()->setContextProperty("memberSelectionCpp",selectLevel);

And the seen member of team 1 is “undefined”

the fungsiReturnID is as follows:

  1. QString memberSelect::fungsiReturnID(int index)
  2. {
  3.     return soapResult.result->__ptr[index]->UserID;
  4. }

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.

June 22, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

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?

June 22, 2011

chronoske chronoske
Lab Rat
31 posts

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

June 22, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

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

  1. ListElement { name: memberSelectionCpp.fungsiReturnID(2); team: 1 }

may be I am wrong…

June 22, 2011

chronoske chronoske
Lab Rat
31 posts

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?

June 22, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

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

July 1, 2011

chronoske chronoske
Lab Rat
31 posts

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

July 1, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

Looks like some good news for you.. You can do it..

  1. ListModel {
  2.             id: myModel
  3.             ListElement { name: "Bob"; team: 2 }
  4.             ListElement { name: "Jane"; team: 3 }
  5.        
  6.            Component.onCompleted: {
  7.                 append({name:memberSelectionCpp.fungsiReturnID(2),team:1})
  8.            }
  9.         }

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.

July 13, 2011

chronoske chronoske
Lab Rat
31 posts

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

July 13, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts
chronoske wrote:
I still can’t figured it how, so I guess I’ll try to change the concept for my project. Thanks everyone!

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

 
  ‹‹ [SOLVED] QML Map Element - center coordinate (loop detection issue)      C++: how to call QML ListView selected item object? ››

You must log in to post a reply. Not a member yet? Register here!