
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheXmlRole element allows you to specify a role for anXmlListModel.More...
| Since: | Qt 4.7 |
See alsoQtDeclarative.
Defines whether this is a key role.
Key roles are used to to determine whether a set of values should be updated or added to the XML list model whenXmlListModel::reload() is called.
See alsoXmlListModel.
The name for the role. This name is used to access the model data for this role.
For example, the following model has a role named "title", which can be accessed from the view's delegate:
XmlListModel {id:xmlModel// ...XmlRole {name:"title"query:"title/string()" }}
ListView {model:xmlModeldelegate:Text {text:title }}
The relative XPath expression query for this role. The query must be relative; it cannot start with a '/'.
For example, if there is an XML document like this:
<?xml version="1.0" encoding="iso-8859-1" ?><catalogue> <book type="Hardcover"> <title>C++ GUI Programming with Qt 4</title> <year>2006</year> <author>Jasmin Blanchette</author> <author>Mark Summerfield</author> </book> <book type="Paperback"> <title>Programming with Qt</title> <year>2002</year> <author>Matthias Kalle Dalheimer</author> </book> </catalogue>
Here are some valid XPath expressions forXmlRole queries on this document:
XmlListModel {id:model ...// XmlRole queries will be made on <book> elementsquery:"/catalogue/book"// query the book titleXmlRole {name:"title";query:"title/string()" }// query the book's yearXmlRole {name:"year";query:"year/number()" }// query the book's type (the '@' indicates 'type' is an attribute, not an element)XmlRole {name:"type";query:"@type/string()" }// query the book's first listed author (note in XPath the first index is 1, not 0)XmlRole {name:"first_author";query:"author[1]/string()" }}
See theW3C XPath 2.0 specification for more information.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.