<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Grantlee: Grantlee for application developers</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Grantlee
   &#160;<span id="projectnumber">5.1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title"><a class="el" href="namespaceGrantlee.html" title="The Grantlee namespace holds all public Grantlee API.">Grantlee</a> for application developers </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Integrating Grantlee into applications is very simple. This page describes</p>
<ul>
<li>How to render a <a class="el" href="classGrantlee_1_1Template.html" title="The Template class is a tree of nodes which may be rendered.">Template</a> with a <a class="el" href="classGrantlee_1_1Context.html" title="The Context class holds the context to render a template with.">Context</a> </li>
<li>How to load Templates </li>
<li>How to extend the syntax of Grantlee </li>
<li>Patterns of use of Grantlee </li>
<li>Differences between Django and Grantlee</li>
</ul>
<p>If you are not already familiar with Django template syntax and structure, start with <a class="el" href="for_themers.html">Grantlee for theme artists.</a>. If you are already familiar with Django, you might find <a class="el" href="differences_django.html">Differences between Django and Grantlee</a> informative.</p>
<h1><a class="anchor" id="rendering_templates"></a>
Rendering Templates</h1>
<h2><a class="anchor" id="creating_templates"></a>
Creating Templates</h2>
<p>Rendering templates is also very easy in application code. A single <a class="el" href="classGrantlee_1_1Template.html" title="The Template class is a tree of nodes which may be rendered.">Template</a> may be rendered multiple times with different <a class="el" href="classGrantlee_1_1Context.html" title="The Context class holds the context to render a template with.">Context</a> objects.</p>
<div class="fragment"><div class="line"><a class="code" href="classGrantlee_1_1Engine.html">Grantlee::Engine</a> *engine = <span class="keyword">new</span> <a class="code" href="classGrantlee_1_1Engine.html">Grantlee::Engine</a>( <span class="keyword">this</span> );</div><div class="line"><a class="code" href="classGrantlee_1_1Template.html">Grantlee::Template</a> t = engine-&gt;<a class="code" href="classGrantlee_1_1Engine.html#a0965b7997bc2794a64c46b644265fe92">newTemplate</a>(<span class="stringliteral">&quot;My name is {{ name }}.&quot;</span>, <span class="stringliteral">&quot;my_template_name&quot;</span>);</div><div class="line">QVariantHash mapping;</div><div class="line">mapping.insert(<span class="stringliteral">&quot;name&quot;</span>, <span class="stringliteral">&quot;Grainne&quot;</span>);</div><div class="line"><a class="code" href="classGrantlee_1_1Context.html">Grantlee::Context</a> c(mapping);</div><div class="line"></div><div class="line">t-&gt;<a class="code" href="classGrantlee_1_1Template.html#a3df963d5f7ecad09962389ede644688e">render</a>(&amp;c); <span class="comment">// Returns &quot;My name is Grainne.&quot;</span></div><div class="line"></div><div class="line">mapping.insert(<span class="stringliteral">&quot;name&quot;</span>, <span class="stringliteral">&quot;Henry&quot;</span>);</div><div class="line">c = <a class="code" href="classGrantlee_1_1Context.html">Grantlee::Context</a>(mapping);</div><div class="line"></div><div class="line">t-&gt;<a class="code" href="classGrantlee_1_1Template.html#a3df963d5f7ecad09962389ede644688e">render</a>(&amp;c); <span class="comment">// Returns &quot;My name is Henry.&quot;</span></div></div><!-- fragment --><p>Ususally, applications will not create a <a class="el" href="classGrantlee_1_1Template.html" title="The Template class is a tree of nodes which may be rendered.">Template</a> directly, but instead use a <a class="el" href="classGrantlee_1_1Engine.html" title="Grantlee::Engine is the main entry point for creating Grantlee Templates.">Grantlee::Engine</a> to load external files. This allows artists to define the template without needing to recompile.</p>
<div class="fragment"><div class="line"><a class="code" href="classGrantlee_1_1Template.html">Grantlee::Template</a> t = engine-&gt;<a class="code" href="classGrantlee_1_1Engine.html#a37d99f171c0bdf6469f1ef05f064d1ce">loadByName</a>(<span class="stringliteral">&quot;template.html&quot;</span>);</div><div class="line"></div><div class="line">t-&gt;<a class="code" href="classGrantlee_1_1Template.html#a3df963d5f7ecad09962389ede644688e">render</a>(&amp;c)</div></div><!-- fragment --><h2><a class="anchor" id="variables"></a>
Variables</h2>
<p>A <a class="el" href="classGrantlee_1_1Context.html" title="The Context class holds the context to render a template with.">Context</a> object maps a string to another object for reference in the template. String keys in the <a class="el" href="classGrantlee_1_1Context.html" title="The Context class holds the context to render a template with.">Context</a> object are available as variables in the <a class="el" href="classGrantlee_1_1Template.html" title="The Template class is a tree of nodes which may be rendered.">Template</a>, and can be used with the <code>{{&#160;variable&#160;}}</code> syntax or inside <code>{%&#160;control&#160;tags&#160;%}</code>. In the above example, we mapped the string <code>"name"</code> to the string <code>"Grainne"</code> and then to the string <code>"Henry"</code>. We can create more than just string mappings though.</p>
<div class="fragment"><div class="line">mapping.insert(<span class="stringliteral">&quot;myint&quot;</span>, 6); <span class="comment">// Can insert ints</span></div><div class="line">mapping.insert(<span class="stringliteral">&quot;mydouble&quot;</span>, 6.5); <span class="comment">// Can insert doubles</span></div><div class="line">mapping.insert(<span class="stringliteral">&quot;mybool&quot;</span>, <span class="keyword">false</span>); <span class="comment">// Can insert bools</span></div><div class="line"></div><div class="line">QVariantList mylist;</div><div class="line">mylist &lt;&lt; <span class="stringliteral">&quot;Ingrid&quot;</span> &lt;&lt; 3;</div><div class="line">mapping.insert(<span class="stringliteral">&quot;mylist&quot;</span>, mylist); <span class="comment">// Can insert QVariantList</span></div><div class="line"></div><div class="line">QVariantHash myhash;</div><div class="line">myhash.insert(<span class="stringliteral">&quot;James&quot;</span>, <span class="stringliteral">&quot;Artist&quot;</span>);</div><div class="line">myhash.insert(<span class="stringliteral">&quot;Kiera&quot;</span>, <span class="stringliteral">&quot;Dreamer&quot;</span>);</div><div class="line">mapping.insert(<span class="stringliteral">&quot;myhash&quot;</span>, myhash); <span class="comment">// Can insert QVariantHash</span></div><div class="line"></div><div class="line">QObject *obj;</div><div class="line">QVariant objVar = QVariant::fromValue(obj);</div><div class="line">mapping.insert(<span class="stringliteral">&quot;myobject&quot;</span>, objVar); <span class="comment">// Can insert QObject*</span></div></div><!-- fragment --><p>It is additionally possible to insert any type of object or any container (not just QVariantHash and QVariantList) into the <a class="el" href="classGrantlee_1_1Context.html" title="The Context class holds the context to render a template with.">Context</a>. </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="generic_types_and_templates.html">Generic type and template support</a>.</dd></dl>
<h1><a class="anchor" id="extending_grantlee"></a>
Extending Grantlee</h1>
<p>Grantlee has 5 extension points.</p>
<ul>
<li>Custom object variables</li>
<li>Generic types and containers</li>
<li>Filters</li>
<li>Tags</li>
<li>Loaders</li>
</ul>
<h2><a class="anchor" id="custom_objects"></a>
Custom objects</h2>
<p>As already noted, <code>QObject*</code> can be inserted into templates. The recommended way to insert custom objects into templates is to create QObject wrappers for your objects. As QObject is introspectable, this will allow lookups to work in a way you define.</p>
<dl class="section note"><dt>Note</dt><dd>If you are already familiar with Django you will know that creating wrappers is not necessary in Django. That is because python objects are already fully introspectable.</dd></dl>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;myperson.h&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">class </span>PersonWrapper : <span class="keyword">public</span> QObject</div><div class="line">{</div><div class="line">  Q_OBJECT</div><div class="line">  Q_PROPERTY(QString name READ name)</div><div class="line"><span class="keyword">public</span>:</div><div class="line">  PersonWrapper(<span class="keyword">const</span> QString &amp;name, <span class="keywordtype">int</span> age);</div><div class="line"></div><div class="line">  QString name() <span class="keyword">const</span>;</div><div class="line"></div><div class="line">  <span class="keywordtype">int</span> age() <span class="keyword">const</span>;</div><div class="line"></div><div class="line">  QString clear();</div><div class="line"></div><div class="line">};</div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">PersonWrapper *linda = <span class="keyword">new</span> PersonWrapper(<span class="stringliteral">&quot;Linda&quot;</span>, 21);</div><div class="line"></div><div class="line">QVariant lindaVar = QVariant::fromValue&lt;QObject*&gt;(linda);</div><div class="line"></div><div class="line">mapping.insert(<span class="stringliteral">&quot;person&quot;</span>, lindaVar);</div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">The name is {{ person.name }} and age is {{ person.age }}.</div><div class="line"></div><div class="line"><span class="comment">// Will be rendered as</span></div><div class="line"><span class="comment">// The name is Linda and age is .</span></div></div><!-- fragment --><p>Note that the 'name' of person is accessible in the template, but the 'age' is not. Note also that rendering fails silently if the method can not be found. Only methods which have a corresponding Q_PROPERTY declaration are accessible from templates. To make age accessible in the template, we would need to add</p>
<pre class="fragment">  Q_PROPERTY(int age READ age)
</pre><p>to the class. Note also that those methods are const. Rendering a template should never change an object it is rendering. Always make sure the READ properties of your wrapper objects are const. It is also possible to lookup dynamic properties of QObjects. In the case of dynamic properties, the property name must be UTF-8 encoded.</p>
<p>Finally, note that the person object (Linda) is inserted into the QVariant as a QObject*, not as a PersonWrapper*. Otherwise, the compiler would generate an error message about an unregistered datatype PersonWrapper*. While using Q_DECLARE_METATYPE(PersonWrapper*) would make the compiler error go away, it would still not be possible to use the Linda object in Grantlee templates. Using <a class="el" href="namespaceGrantlee.html#ad8e66694604688cb9402241f444deda3" title="Registers the type RealType with the metatype system.">Grantlee::registerMetaType</a>&lt;PersonWrapper*&gt;() would work, but it is recommended to use QObject* instead. See also <a class="el" href="for_app_dev.html#custom_object_properties">Custom Object Properties</a>.</p>
<p>If you already have QObjects in your application which would be suitable for use in templates, you only need to add some Q_PROPERTY entries to the classes to make them accessible to Grantlee.</p>
<dl class="section note"><dt>Note</dt><dd>If you are familiar with Django you may be aware of the alters_data attribute for methods. This method of using wrappers and const is the equivalent to the alters_data attribute. You the wrapper writer choose the properties which will be accessible from the templates and makes them const, so there's no need to mark other methods as alters_data.</dd></dl>
<p>For most uses of Grantlee, this is enough to get make an application themable easily and quickly. For more advanced usage, see <a class="el" href="extension.html">Extending the template system</a>. For some example uses of Grantlee, see <a class="el" href="examples.html">Examples of Grantlee use</a>.</p>
<h2><a class="anchor" id="custom_object_properties"></a>
Custom Object Properties</h2>
<p>In Qt4 there are some limitations regarding the types that may be used in Q_PROPERTY entries which should be read by Grantlee.</p>
<p>We might define a Home object like this:</p>
<div class="fragment"><div class="line"><span class="keyword">class </span>Home : <span class="keyword">public</span> QObject</div><div class="line">{</div><div class="line">    Q_OBJECT</div><div class="line">    Q_PROPERTY(<span class="keywordtype">int</span> houseNumber READ houseNumber)</div><div class="line">    Q_PROPERTY(QString streetName READ streetName)</div><div class="line">    Q_PROPERTY(QString city READ city)</div><div class="line"><span class="keyword">public</span>:</div><div class="line">    <span class="comment">// ...</span></div><div class="line">};</div><div class="line">Q_DECLARE_METATYPE(Home*)</div></div><!-- fragment --><p>And we may wish to use it in our PersonWrapper object:</p>
<div class="fragment"><div class="line"><span class="keyword">class </span>PersonWrapper : <span class="keyword">public</span> QObject</div><div class="line">{</div><div class="line">  Q_OBJECT</div><div class="line">  Q_PROPERTY(QString name READ name)</div><div class="line">  Q_PROPERTY(Home* home READ home)</div><div class="line"><span class="keyword">public</span>:</div><div class="line">  PersonWrapper(<span class="keyword">const</span> QString &amp;name, <span class="keywordtype">int</span> age, Home *home);</div><div class="line"></div><div class="line">  Home* home() <span class="keyword">const</span>;</div><div class="line"></div><div class="line">  <span class="comment">// ...</span></div><div class="line">}</div></div><!-- fragment --><p>And then use it in a template:</p>
<div class="fragment"><div class="line">&lt;h1&gt;{{ person.name }}&lt;/h1&gt;</div><div class="line">House number: {{ person.home.houseNumber }}</div><div class="line">Street: {{ person.home.streetName }}</div></div><!-- fragment --><p>This will not work with Qt4. The home property will not be readable and there will be a message about an unregistered datatype 'Home*'.</p>
<p>The workaround is to specify the type of the home property to be a QObject* instead of a Home*:</p>
<div class="fragment"><div class="line"><span class="keyword">class </span>PersonWrapper : <span class="keyword">public</span> QObject</div><div class="line">{</div><div class="line">  Q_OBJECT</div><div class="line">  Q_PROPERTY(QString name READ name)</div><div class="line">  Q_PROPERTY(QObject* home READ scriptableHome)</div><div class="line"><span class="keyword">public</span>:</div><div class="line">  PersonWrapper(<span class="keyword">const</span> QString &amp;name, <span class="keywordtype">int</span> age, Home *home);</div><div class="line"></div><div class="line">  QObject* scriptableHome()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> home(); }</div><div class="line">  Home* home() <span class="keyword">const</span>;</div><div class="line"></div><div class="line">  <span class="comment">// ...</span></div><div class="line">}</div></div><!-- fragment --><p>In this example, we leave the home() method intact because we may want to use the Home* type from C++, but we add a scriptableHome() method which returns a QObject* instead of a Home*. This method is then used in the READ component of the Q_PROPERTY.</p>
<p>The above is the recommended method of using Q_PROPERTY with QObject derived types, however, if the class containing the Q_PROPERTY (PersonWrapper in the example above) can not be modified, it is still possible to make the property accessible to Grantlee by using the <a class="el" href="namespaceGrantlee.html#ad8e66694604688cb9402241f444deda3" title="Registers the type RealType with the metatype system.">Grantlee::registerMetaType()</a> method near the start of the program.</p>
<div class="fragment"><div class="line"><span class="comment">// Somewhere among other initializers</span></div><div class="line">Grantlee::registerMetaType&lt;Home*&gt;();</div><div class="line"></div><div class="line"><span class="comment">// ...</span></div><div class="line"><span class="comment">// Creating the context.</span></div><div class="line"></div><div class="line">PersonWrapper *person = <span class="keyword">new</span> PersonWrapper;</div><div class="line"></div><div class="line">context.insert(<span class="stringliteral">&quot;person&quot;</span>, person);</div><div class="line"></div><div class="line">t-&gt;<a class="code" href="classGrantlee_1_1Template.html#a3df963d5f7ecad09962389ede644688e">render</a>(&amp;c);</div><div class="line"></div><div class="line"><span class="comment">// ...</span></div><div class="line"><span class="comment">// Template can now use home property as normal. Eg</span></div><div class="line"> Street: {{ person.home.streetName }}</div></div><!-- fragment --><p>Note that prior to Grantlee version 0.1.9, <a class="el" href="namespaceGrantlee.html#ad8e66694604688cb9402241f444deda3" title="Registers the type RealType with the metatype system.">Grantlee::registerMetaType</a>&lt;Home*, QObject*&gt;(); must be used instead.</p>
<p>Using containers such as QList with Q_PROPERTY macro is also possible.</p>
<div class="fragment"><div class="line"><span class="keyword">class </span>PersonWrapper : <span class="keyword">public</span> QObject</div><div class="line">{</div><div class="line">  Q_OBJECT</div><div class="line">  Q_PROPERTY(QString name READ name)</div><div class="line">  Q_PROPERTY(QVariant friends READ friends)</div><div class="line"><span class="keyword">public</span>:</div><div class="line">  PersonWrapper(<span class="keyword">const</span> QString &amp;name, <span class="keywordtype">int</span> age, Home *home);</div><div class="line"></div><div class="line">  QVariant friends()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> QVariant::fromValue(m_friends); }</div><div class="line">  <span class="keywordtype">void</span> setFriends(<span class="keyword">const</span> QList&lt;QObject*&gt; friends) { m_friends = friends; }</div><div class="line"></div><div class="line">  <span class="comment">// ...</span></div><div class="line"></div><div class="line"><span class="keyword">private</span>:</div><div class="line">  QList&lt;QObject*&gt; m_friends;</div><div class="line">};</div><div class="line">Q_DECLARE_METATYPE(QList&lt;QObject*&gt;)</div></div><!-- fragment --><p>It is also necessary to register QList&lt;QObject*&gt; with the Qt metatype system and with <a class="el" href="namespaceGrantlee.html" title="The Grantlee namespace holds all public Grantlee API.">Grantlee</a></p>
<div class="fragment"><div class="line">Grantlee::registerSequentialContainer&lt;QList&lt;QObject*&gt; &gt;();</div></div><!-- fragment --><h2><a class="anchor" id="generic_variables"></a>
generic_variables</h2>
<p>An alternative to writing wrapper QObject classes with Q_PROPERTY macros is to use the Grantlee::MetaType system to provide introspection for any type or any container. This subject is treated in detail in <a class="el" href="generic_types_and_templates.html">Generic type and template support</a></p>
<h2><a class="anchor" id="enumerator_variables"></a>
Enumerators</h2>
<p>Grantlee has built-in support for enumerators which use the Q_ENUMS macro.</p>
<div class="fragment"><div class="line"><span class="keyword">class </span>MyClass : <span class="keyword">public</span> QObject</div><div class="line">{</div><div class="line">  Q_OBJECT</div><div class="line">  Q_ENUMS(PersonName)</div><div class="line">  Q_PROPERTY(PersonName personName READ personName)</div><div class="line"><span class="keyword">public</span>:</div><div class="line"></div><div class="line">  <span class="keyword">enum</span> PersonName</div><div class="line">  {</div><div class="line">    Mike,</div><div class="line">    Natalie,</div><div class="line">    Oliver,</div><div class="line">    Patrica = 9</div><div class="line">    Quentin</div><div class="line">  };</div><div class="line"></div><div class="line">  MyClass(QObject *parent = 0 );</div><div class="line"></div><div class="line">  PersonName personName()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> Quentin; }</div><div class="line"></div><div class="line">};</div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">{</div><div class="line">  QObject *<span class="keywordtype">object</span> = <span class="keyword">new</span> MyClass(<span class="keyword">this</span>);</div><div class="line">  context.insert(<span class="stringliteral">&quot;myObj&quot;</span>, <span class="keywordtype">object</span>);</div><div class="line">  t-&gt;<a class="code" href="classGrantlee_1_1Template.html#a3df963d5f7ecad09962389ede644688e">render</a>(context);</div><div class="line">}</div></div><!-- fragment --><p>The enums can be used and accessed in various ways. See QMetaEnum for details.</p>
<div class="fragment"><div class="line">Oliver is value {{ myObj.Oliver }}.</div><div class="line"><span class="comment">// Output: &quot;Oliver is value 2&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">Oliver key is {{ myObj.Oliver.key }}.</div><div class="line"><span class="comment">// Output: &quot;Oliver key is Oliver&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">Oliver value is {{ myObj.Oliver.value }}.</div><div class="line"><span class="comment">// Output: &quot;Oliver value is 2&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">Oliver scope is {{ myObj.Oliver.scope }}.</div><div class="line"><span class="comment">// Output: &quot;Oliver scope is MyClass&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">Oliver scope is {{ myObj.Oliver.name }}.</div><div class="line"><span class="comment">// Output: &quot;Oliver scope is PersonName&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">Patrica is value {{ myObj.Patrica }}.</div><div class="line"><span class="comment">// Output: &quot;Patrica is value 9&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">PersonName has {{ myObj.PersonName.keyCount }} items.</div><div class="line"><span class="comment">// Output: &quot;PersonName has 5 items&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">Second item is {{ myObj.PersonName.1 }}.</div><div class="line"><span class="comment">// Output: &quot;Second item is 1&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">Second item is {{ myObj.PersonName.1.key }}.</div><div class="line"><span class="comment">// Output: &quot;Second item is Natalie&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">Fourth item is {{ myObj.PersonName.3 }}.</div><div class="line"><span class="comment">// Output: &quot;Fourth item is 9&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">Fourth item is {{ myObj.PersonName.3.key }}.</div><div class="line"><span class="comment">// Output: &quot;Fourth item is Patrica&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">The personName <span class="keyword">property</span> is {{ myObj.personName }}.</div><div class="line"><span class="comment">// Output: &quot;The personName property is 10&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">The personName <span class="keyword">property</span> is {{ myObj.personName.key }}.</div><div class="line"><span class="comment">// Output: &quot;The personName property is Quentin&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">The personName type is {{ myObj.personName.scope }}.</div><div class="line"><span class="comment">// Output: &quot;The personName type is PersonName&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">The personName is {% with myObj.personName as var %}{{ var }}, {{ var.key }}{% endwith %}.</div><div class="line"><span class="comment">// Output: &quot;The personName is 10, Quentin&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">The <span class="keyword">enum</span> is {% with myObj.PersonName as <span class="keyword">enum</span> %}{{ <span class="keyword">enum</span>.3 }}, {{ <span class="keyword">enum</span>.4 }}, {{ <span class="keyword">enum</span>.4.key }}{% endwith %}.</div><div class="line"><span class="comment">// Output: &quot;The enum is 9, 10, Quentin&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">The <span class="keyword">enum</span> is {% <span class="keywordflow">for</span> <span class="keyword">enum</span> in myObj.PersonName %}{{ <span class="keyword">enum</span> }} : {{ <span class="keyword">enum</span>.key }}, {% endfor %}.</div><div class="line"><span class="comment">// Output: &quot;The enum 0 : Mike, 1 : Natalie, 2 : Oliver, 9 : Patrica, 10 : Quentin, &quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">The <span class="keyword">enum</span> is {% <span class="keywordflow">for</span> <span class="keyword">enum</span> in myObj.PersonName %}</div><div class="line">                {% ifequal <span class="keyword">enum</span> Oliver %}**{{ <span class="keyword">enum</span> }} : {{ <span class="keyword">enum</span>.key }}**</div><div class="line">                {% <span class="keywordflow">else</span> %}{{ <span class="keyword">enum</span> }} : {{ <span class="keyword">enum</span>.key }},</div><div class="line">                {% endifequal %}</div><div class="line">            {% endfor %}.</div><div class="line"><span class="comment">// Output: &quot;The enum 0 : Mike, 1 : Natalie, **2 : Oliver**, 9 : Patrica, 10 : Quentin, &quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">The <span class="keyword">enum</span> is {% <span class="keywordflow">for</span> <span class="keyword">enum</span> in myObj.PersonName %}</div><div class="line">                {% ifequal <span class="keyword">enum</span> myObj.personName %}**{{ <span class="keyword">enum</span> }} : {{ <span class="keyword">enum</span>.key }}**</div><div class="line">                {% <span class="keywordflow">else</span> %}{{ <span class="keyword">enum</span> }} : {{ <span class="keyword">enum</span>.key }},</div><div class="line">                {% endifequal %}</div><div class="line">            {% endfor %}.</div><div class="line"><span class="comment">// Output: &quot;The enum 0 : Mike, 1 : Natalie, 2 : Oliver, 9 : Patrica, **10 : Quentin**, &quot;.</span></div></div><!-- fragment --><p>Enumerators in the Qt namespaces are also supported.</p>
<div class="fragment"><div class="line">AlignRight value is {{ Qt.AlignRight }}.</div><div class="line"><span class="comment">// Output: &quot;AlignRight value is 2&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">AlignRight key is {{ Qt.AlignRight.key }}.</div><div class="line"><span class="comment">// Output: &quot;AlignRight value is AlignRight&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">AlignRight scope is {{ Qt.AlignRight.scope }}.</div><div class="line"><span class="comment">// Output: &quot;AlignRight scope is Qt&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">AlignRight name is {{ Qt.AlignRight.name }}.</div><div class="line"><span class="comment">// Output: &quot;AlignRight scope is Alignment&quot;.</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">{% ifequal myObj.alignment Qt.AlignRight %}RightAligned{% <span class="keywordflow">else</span> %}Not RightAligned{% endifequal %}.</div><div class="line"><span class="comment">// Output: &quot;RightAligned&quot;. or &quot;Not RightAligned&quot;, depending on the value of myObj.alignment.</span></div><div class="line"></div><div class="line">...</div></div><!-- fragment --> </div></div><!-- PageDoc -->
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.15
</small></address>
</body>
</html>
