<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qqmlpropertymap.cpp --> <title>QQmlPropertyMap Class | Qt QML 5.9</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.9</td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-module.html">C++ Classes</a></td><td >QQmlPropertyMap</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</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="#public-functions">Public Functions</a></li> <li class="level1"><a href="#signals">Signals</a></li> <li class="level1"><a href="#protected-functions">Protected Functions</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">QQmlPropertyMap Class</h1> <!-- $$$QQmlPropertyMap-brief --> <p>The <a href="qqmlpropertymap.html">QQmlPropertyMap</a> class allows you to set key-value pairs that can be used in QML bindings. <a href="#details">More...</a></p> <!-- @@@QQmlPropertyMap --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QQmlPropertyMap></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += qml</td></tr></table></div><ul> <li><a href="qqmlpropertymap-members.html">List of all members, including inherited members</a></li> </ul> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#QQmlPropertyMap">QQmlPropertyMap</a></b>(QObject *<i>parent</i> = Q_NULLPTR)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#dtor.QQmlPropertyMap">~QQmlPropertyMap</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#clear">clear</a></b>(const QString &<i>key</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#contains">contains</a></b>(const QString &<i>key</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#count">count</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#insert">insert</a></b>(const QString &<i>key</i>, const QVariant &<i>value</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#isEmpty">isEmpty</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QStringList </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#keys">keys</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#size">size</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QVariant </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#value">value</a></b>(const QString &<i>key</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QVariant &</td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#operator-5b-5d">operator[]</a></b>(const QString &<i>key</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QVariant </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#operator-5b-5d-1">operator[]</a></b>(const QString &<i>key</i>) const</td></tr> </table></div> <a name="signals"></a> <h2 id="signals">Signals</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#valueChanged">valueChanged</a></b>(const QString &<i>key</i>, const QVariant &<i>value</i>)</td></tr> </table></div> <a name="protected-functions"></a> <h2 id="protected-functions">Protected Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#QQmlPropertyMap-1">QQmlPropertyMap</a></b>(DerivedType *<i>derived</i>, QObject *<i>parent</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual QVariant </td><td class="memItemRight bottomAlign"><b><a href="qqmlpropertymap.html#updateValue">updateValue</a></b>(const QString &<i>key</i>, const QVariant &<i>input</i>)</td></tr> </table></div> <a name="details"></a> <!-- $$$QQmlPropertyMap-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qqmlpropertymap.html">QQmlPropertyMap</a> class allows you to set key-value pairs that can be used in QML bindings.</p> <p><a href="qqmlpropertymap.html">QQmlPropertyMap</a> provides a convenient way to expose domain data to the UI layer. The following example shows how you might declare data in C++ and then access it in QML.</p> <p>In the C++ file:</p> <pre class="cpp"> <span class="comment">// create our data</span> <span class="type"><a href="qqmlpropertymap.html#QQmlPropertyMap">QQmlPropertyMap</a></span> ownerData; ownerData<span class="operator">.</span>insert(<span class="string">"name"</span><span class="operator">,</span> <span class="type">QVariant</span>(<span class="type">QString</span>(<span class="string">"John Smith"</span>))); ownerData<span class="operator">.</span>insert(<span class="string">"phone"</span><span class="operator">,</span> <span class="type">QVariant</span>(<span class="type">QString</span>(<span class="string">"555-5555"</span>))); <span class="comment">// expose it to the UI layer</span> <span class="type">QQuickView</span> view; <span class="type"><a href="qqmlcontext.html">QQmlContext</a></span> <span class="operator">*</span>ctxt <span class="operator">=</span> view<span class="operator">.</span>rootContext(); ctxt<span class="operator">-</span><span class="operator">></span>setContextProperty(<span class="string">"owner"</span><span class="operator">,</span> <span class="operator">&</span>ownerData); view<span class="operator">.</span>setSource(<span class="type">QUrl</span><span class="operator">::</span>fromLocalFile(<span class="string">"main.qml"</span>)); view<span class="operator">.</span>show(); </pre> <p>Then, in <code>main.qml</code>:</p> <pre class="cpp"> Text { text: owner<span class="operator">.</span>name <span class="operator">+</span> <span class="string">" "</span> <span class="operator">+</span> owner<span class="operator">.</span>phone } </pre> <p>The binding is dynamic - whenever a key's value is updated, anything bound to that key will be updated as well.</p> <p>To detect value changes made in the UI layer you can connect to the <a href="qqmlpropertymap.html#valueChanged">valueChanged</a>() signal. However, note that <a href="qqmlpropertymap.html#valueChanged">valueChanged</a>() is <b>NOT</b> emitted when changes are made by calling <a href="qqmlpropertymap.html#insert">insert</a>() or <a href="qqmlpropertymap.html#clear">clear</a>() - it is only emitted when a value is updated from QML.</p> <p><b>Note: </b>It is not possible to remove keys from the map; once a key has been added, you can only modify or clear its associated value.</p><p><b>Note: </b>When deriving a class from <a href="qqmlpropertymap.html">QQmlPropertyMap</a>, use the <a href="qqmlpropertymap.html#QQmlPropertyMap-1">protected two-argument constructor</a> which ensures that the class is correctly registered with the Qt Meta-Object System.</p></div> <!-- @@@QQmlPropertyMap --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QQmlPropertyMap[overload1]$$$QQmlPropertyMapQObject* --> <h3 class="fn" id="QQmlPropertyMap"><a name="QQmlPropertyMap"></a>QQmlPropertyMap::<span class="name">QQmlPropertyMap</span>(<span class="type">QObject</span> *<i>parent</i> = Q_NULLPTR)</h3> <p>Constructs a bindable map with parent object <i>parent</i>.</p> <!-- @@@QQmlPropertyMap --> <!-- $$$QQmlPropertyMap$$$QQmlPropertyMapDerivedType*QObject* --> <h3 class="fn" id="QQmlPropertyMap-1"><a name="QQmlPropertyMap-1"></a><code>[protected] </code>QQmlPropertyMap::<span class="name">QQmlPropertyMap</span>(<span class="type">DerivedType</span> *<i>derived</i>, <span class="type">QObject</span> *<i>parent</i>)</h3> <p>Constructs a bindable map with parent object <i>parent</i>. Use this constructor in classes derived from <a href="qqmlpropertymap.html">QQmlPropertyMap</a>.</p> <p>The type of <i>derived</i> is used to register the property map with the Meta-Object System, which is necessary to ensure that properties of the derived class are accessible. This type must be derived from <a href="qqmlpropertymap.html">QQmlPropertyMap</a>.</p> <!-- @@@QQmlPropertyMap --> <!-- $$$~QQmlPropertyMap[overload1]$$$~QQmlPropertyMap --> <h3 class="fn" id="dtor.QQmlPropertyMap"><a name="dtor.QQmlPropertyMap"></a><code>[virtual] </code>QQmlPropertyMap::<span class="name">~QQmlPropertyMap</span>()</h3> <p>Destroys the bindable map.</p> <!-- @@@~QQmlPropertyMap --> <!-- $$$clear[overload1]$$$clearconstQString& --> <h3 class="fn" id="clear"><a name="clear"></a><span class="type">void</span> QQmlPropertyMap::<span class="name">clear</span>(const <span class="type">QString</span> &<i>key</i>)</h3> <p>Clears the value (if any) associated with <i>key</i>.</p> <!-- @@@clear --> <!-- $$$contains[overload1]$$$containsconstQString& --> <h3 class="fn" id="contains"><a name="contains"></a><span class="type">bool</span> QQmlPropertyMap::<span class="name">contains</span>(const <span class="type">QString</span> &<i>key</i>) const</h3> <p>Returns true if the map contains <i>key</i>.</p> <p><b>See also </b><a href="qqmlpropertymap.html#size">size</a>().</p> <!-- @@@contains --> <!-- $$$count[overload1]$$$count --> <h3 class="fn" id="count"><a name="count"></a><span class="type">int</span> QQmlPropertyMap::<span class="name">count</span>() const</h3> <p>This is an overloaded function.</p> <p>Same as <a href="qqmlpropertymap.html#size">size</a>().</p> <!-- @@@count --> <!-- $$$insert[overload1]$$$insertconstQString&constQVariant& --> <h3 class="fn" id="insert"><a name="insert"></a><span class="type">void</span> QQmlPropertyMap::<span class="name">insert</span>(const <span class="type">QString</span> &<i>key</i>, const <span class="type">QVariant</span> &<i>value</i>)</h3> <p>Sets the value associated with <i>key</i> to <i>value</i>.</p> <p>If the key doesn't exist, it is automatically created.</p> <!-- @@@insert --> <!-- $$$isEmpty[overload1]$$$isEmpty --> <h3 class="fn" id="isEmpty"><a name="isEmpty"></a><span class="type">bool</span> QQmlPropertyMap::<span class="name">isEmpty</span>() const</h3> <p>Returns true if the map contains no keys; otherwise returns false.</p> <p><b>See also </b><a href="qqmlpropertymap.html#size">size</a>().</p> <!-- @@@isEmpty --> <!-- $$$keys[overload1]$$$keys --> <h3 class="fn" id="keys"><a name="keys"></a><span class="type">QStringList</span> QQmlPropertyMap::<span class="name">keys</span>() const</h3> <p>Returns the list of keys.</p> <p>Keys that have been cleared will still appear in this list, even though their associated values are invalid QVariants.</p> <!-- @@@keys --> <!-- $$$size[overload1]$$$size --> <h3 class="fn" id="size"><a name="size"></a><span class="type">int</span> QQmlPropertyMap::<span class="name">size</span>() const</h3> <p>Returns the number of keys in the map.</p> <p><b>See also </b><a href="qqmlpropertymap.html#isEmpty">isEmpty</a>() and <a href="qqmlpropertymap.html#count">count</a>().</p> <!-- @@@size --> <!-- $$$updateValue[overload1]$$$updateValueconstQString&constQVariant& --> <h3 class="fn" id="updateValue"><a name="updateValue"></a><code>[virtual protected] </code><span class="type">QVariant</span> QQmlPropertyMap::<span class="name">updateValue</span>(const <span class="type">QString</span> &<i>key</i>, const <span class="type">QVariant</span> &<i>input</i>)</h3> <p>Returns the new value to be stored for the key <i>key</i>. This function is provided to intercept updates to a property from QML, where the value provided from QML is <i>input</i>.</p> <p>Override this function to manipulate the property value as it is updated. Note that this function is only invoked when the value is updated from QML.</p> <!-- @@@updateValue --> <!-- $$$value[overload1]$$$valueconstQString& --> <h3 class="fn" id="value"><a name="value"></a><span class="type">QVariant</span> QQmlPropertyMap::<span class="name">value</span>(const <span class="type">QString</span> &<i>key</i>) const</h3> <p>Returns the value associated with <i>key</i>.</p> <p>If no value has been set for this key (or if the value has been cleared), an invalid QVariant is returned.</p> <!-- @@@value --> <!-- $$$valueChanged[overload1]$$$valueChangedconstQString&constQVariant& --> <h3 class="fn" id="valueChanged"><a name="valueChanged"></a><code>[signal] </code><span class="type">void</span> QQmlPropertyMap::<span class="name">valueChanged</span>(const <span class="type">QString</span> &<i>key</i>, const <span class="type">QVariant</span> &<i>value</i>)</h3> <p>This signal is emitted whenever one of the values in the map is changed. <i>key</i> is the key corresponding to the <i>value</i> that was changed.</p> <p><b>Note: </b>valueChanged() is <b>NOT</b> emitted when changes are made by calling <a href="qqmlpropertymap.html#insert">insert</a>() or <a href="qqmlpropertymap.html#clear">clear</a>() - it is only emitted when a value is updated from QML.</p><!-- @@@valueChanged --> <!-- $$$operator[][overload1]$$$operator[]constQString& --> <h3 class="fn" id="operator-5b-5d"><a name="operator-5b-5d"></a><span class="type">QVariant</span> &QQmlPropertyMap::<span class="name">operator[]</span>(const <span class="type">QString</span> &<i>key</i>)</h3> <p>Returns the value associated with the key <i>key</i> as a modifiable reference.</p> <p>If the map contains no item with key <i>key</i>, the function inserts an invalid QVariant into the map with key <i>key</i>, and returns a reference to it.</p> <p><b>See also </b><a href="qqmlpropertymap.html#insert">insert</a>() and <a href="qqmlpropertymap.html#value">value</a>().</p> <!-- @@@operator[] --> <!-- $$$operator[]$$$operator[]constQString& --> <h3 class="fn" id="operator-5b-5d-1"><a name="operator-5b-5d-1"></a><span class="type">QVariant</span> QQmlPropertyMap::<span class="name">operator[]</span>(const <span class="type">QString</span> &<i>key</i>) const</h3> <p>This is an overloaded function.</p> <p>Same as <a href="qqmlpropertymap.html#value">value</a>().</p> <!-- @@@operator[] --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2017 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>