<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qqmlxmllistmodel.cpp --> <title>XmlRole QML Type | Qt XML Patterns 5.12.6</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.12</td><td ><a href="qtxmlpatterns-index.html">Qt XML Patterns</a></td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtxmlpatterns-index.html">Qt 5.12.6 Reference Documentation</a></td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#properties">Properties</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">XmlRole QML Type</h1> <span class="subtitle"></span> <!-- $$$XmlRole-brief --> <p>For specifying a role to an <a href="qml-qtquick-xmllistmodel-xmllistmodel.html">XmlListModel</a>. <a href="#details">More...</a></p> <!-- @@@XmlRole --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Import Statement:</td><td class="memItemRight bottomAlign"> import QtQuick.XmlListModel 2.12</td></tr></table></div><ul> <li><a href="qml-qtquick-xmllistmodel-xmlrole-members.html">List of all members, including inherited members</a></li> </ul> <a name="properties"></a> <h2 id="properties">Properties</h2> <ul> <li class="fn"><b><b><a href="qml-qtquick-xmllistmodel-xmlrole.html#isKey-prop">isKey</a></b></b> : bool</li> <li class="fn"><b><b><a href="qml-qtquick-xmllistmodel-xmlrole.html#name-prop">name</a></b></b> : string</li> <li class="fn"><b><b><a href="qml-qtquick-xmllistmodel-xmlrole.html#query-prop">query</a></b></b> : string</li> </ul> <!-- $$$XmlRole-description --> <a name="details"></a> <h2 id="details">Detailed Description</h2> <p><b>See also </b>Qt QML.</p> <!-- @@@XmlRole --> <h2>Property Documentation</h2> <!-- $$$isKey --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="isKey-prop"> <td class="tblQmlPropNode"><p> <a name="isKey-prop"></a><span class="name">isKey</span> : <span class="type">bool</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>Defines whether this is a key role. Key roles are used to determine whether a set of values should be updated or added to the XML list model when <a href="qml-qtquick-xmllistmodel-xmllistmodel.html#reload-method">XmlListModel::reload()</a> is called.</p> <p><b>See also </b><a href="qml-qtquick-xmllistmodel-xmllistmodel.html">XmlListModel</a>.</p> </div></div><!-- @@@isKey --> <br/> <!-- $$$name --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="name-prop"> <td class="tblQmlPropNode"><p> <a name="name-prop"></a><span class="name">name</span> : <span class="type">string</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>The name for the role. This name is used to access the model data for this role.</p> <p>For example, the following model has a role named "title", which can be accessed from the view's delegate:</p> <pre class="qml"> </pre> <pre class="qml"> </pre> </div></div><!-- @@@name --> <br/> <!-- $$$query --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="query-prop"> <td class="tblQmlPropNode"><p> <a name="query-prop"></a><span class="name">query</span> : <span class="type">string</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>The relative XPath expression query for this role. The query must be relative; it cannot start with a '/'.</p> <p>For example, if there is an XML document like this:</p> <pre class="cpp"> </pre> <p>Here are some valid XPath expressions for <a href="qml-qtquick-xmllistmodel-xmlrole.html">XmlRole</a> queries on this document:</p> <pre class="qml"> XmlListModel { id: model ... // XmlRole queries will be made on <book> elements query: "/catalog/book" // query the book title XmlRole { name: "title"; query: "title/string()" } // query the book's year XmlRole { 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()" } // query the wanted attribute as a boolean XmlRole { name: "wanted"; query: "boolean(@wanted)" } } </pre> <p>Accessing the model data for the above roles from a delegate:</p> <pre class="qml"> ListView { width: 300; height: 200 model: model delegate: Column { Text { text: title + " (" + type + ")"; font.bold: wanted } Text { text: first_author } Text { text: year } } </pre> <p>See the <a href="http://www.w3.org/TR/xpath20/">W3C XPath 2.0 specification</a> for more information.</p> </div></div><!-- @@@query --> <br/> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> 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. </p> </div> </body> </html>