Hi Thomas, Element ids are only accessible within the component where they are declared (in the example below, element1 would only be accessible within rowComponent). One of the reasons for this is that a component can be instantiated many times -- for example a ListView will instantiate its delegate once for every row -- and we don't want to end up with many elements sharing the same 'global' id.
Here are a couple ideas of some things you could try (depending on how the program is structured): * putting the save() function within topRow * adding properties to topRow (which become the "public API" of any items instantiated by rowComponent (you'll still need a way to address the right element in the list, though)) * passing the text as a parameter to save() (if the button lives within the delegate) Regards, Michael On 26/02/2011, at 1:24 AM, ext Thomas PABST wrote: Hi, In fact, the ListView is use in first place to show informations details from a contactList. I want add a new contact to the model. The RowElement contain an QML TextEdit Element which load a virtual keyboard. This virtual keyboard insert values on Each TextEdit. So the goal is to save new values when user click a button. That's the purpose of the function saveContact(). I don't want save the value in first place, but after, only if the user click on the save button. That's why I want to get the value. ----------------------------------------------------- Thomas PABST [email protected]<mailto:[email protected]> 2011/2/25 Tobias Renz <[email protected]<mailto:[email protected]>> Hi, If your code example below is right I think you might be wrong on how to use the list view. Typically you would set your values in the data model ListModel { id: data ListElement { value: "value1" } ListElement { value: "value2" } ListElement { value: "value3" } } Setting it to the listView would be the same as you did: ListView { id: listView ... model: data delegate: rowComponent } // End of ListView id: listView But then the delegate would only be one element of the list. The list itself would generate the elements in the "column". Component { id: rowComponent Text { id: element value: model.value text: model.value } => The ListView will now show three Text-Elements below each other in a List or "Column". Showing the value. The key is that you bind the value from the model to the element in the list. Then the value is already stored in the model which you call data. If you want to change the value you would directly change it in the model then the value in the list aka in the delegate will also change. But I'm not sure if this is the intended use of your program or if you want to do something special with ListView? Regards, Tobias Date: Fri, 25 Feb 2011 13:04:06 +0100 From: Thomas PABST <[email protected]<mailto:[email protected]>> Subject: [Qt-qml] Access to element property To: "qt-qml.qt.nokia.com<http://qt-qml.qt.nokia.com/>" <[email protected]<mailto:[email protected]>> Message-ID: <[email protected]<mailto:[email protected]>> Content-Type: text/plain; charset="utf-8" Hi, I'm currently trying to get value from an QML element which is the delegate of a ListView, but the variable cannot be found. With the function saveData() I would like to get the value from RowElement where the id is element1. But qmlViewer return a ReferenceError: Can't find variable: element1. Is there a way to get it ? The following example implement only properties necessary to understand the problem. thanks Item { id: main property variant data function saveData() { data.value = element1.value; ... } ListView { id: listView ... model: data delegate: rowComponent } // End of ListView id: listView Component { id: rowComponent Column { id: topRow RowElement { id: element1 value: "value1" } RowElement { id: element2 value: "value2" } RowElement { id: element3 value: "value3" } }// End of Column id: topRow } // End of Component id: rowComponent } ----------------------------------------------------- Thomas PABST [email protected]<mailto:[email protected]> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110225/a74c395f/attachment.html ------------------------------ _______________________________________________ Qt-qml mailing list [email protected]<mailto:[email protected]> http://lists.qt.nokia.com/mailman/listinfo/qt-qml End of Qt-qml Digest, Vol 3, Issue 37 ************************************* _______________________________________________ Qt-qml mailing list [email protected]<mailto:[email protected]> http://lists.qt.nokia.com/mailman/listinfo/qt-qml <ATT00001..txt>
_______________________________________________ Qt-qml mailing list [email protected] http://lists.qt.nokia.com/mailman/listinfo/qt-qml
