1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qdeclarativeexpression.cpp -->
<title>Qt 4.8: QDeclarativeExpression Class Reference</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="content">
<a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
</div>
<div class="breadcrumb toolblock">
<ul>
<li class="first"><a href="index.html">Home</a></li>
<!-- Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtdeclarative.html">QtDeclarative</a></li>
<li>QDeclarativeExpression</li>
</ul>
</div>
</div>
<div class="content mainContent">
<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="#details">Detailed Description</a></li>
</ul>
</div>
<h1 class="title">QDeclarativeExpression Class Reference</h1>
<!-- $$$QDeclarativeExpression-brief -->
<p>The QDeclarativeExpression class evaluates JavaScript in a QML context. <a href="#details">More...</a></p>
<!-- @@@QDeclarativeExpression -->
<pre class="cpp"> <span class="preprocessor">#include <QDeclarativeExpression></span></pre><p><b>Inherits: </b><a href="qobject.html">QObject</a>.</p>
<p>This class was introduced in Qt 4.7.</p>
<ul>
<li><a href="qdeclarativeexpression-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#QDeclarativeExpression">QDeclarativeExpression</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#QDeclarativeExpression-2">QDeclarativeExpression</a></b> ( QDeclarativeContext * <i>ctxt</i>, QObject * <i>scope</i>, const QString & <i>expression</i>, QObject * <i>parent</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#dtor.QDeclarativeExpression">~QDeclarativeExpression</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#clearError">clearError</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDeclarativeContext * </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#context">context</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDeclarativeEngine * </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#engine">engine</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDeclarativeError </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#error">error</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QVariant </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#evaluate">evaluate</a></b> ( bool * <i>valueIsUndefined</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#expression">expression</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#hasError">hasError</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#lineNumber">lineNumber</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#notifyOnValueChanged">notifyOnValueChanged</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QObject * </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#scopeObject">scopeObject</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#setExpression">setExpression</a></b> ( const QString & <i>expression</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#setNotifyOnValueChanged">setNotifyOnValueChanged</a></b> ( bool <i>notifyOnChange</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#setSourceLocation">setSourceLocation</a></b> ( const QString & <i>url</i>, int <i>line</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#sourceFile">sourceFile</a></b> () const</td></tr>
</table>
<ul>
<li class="fn">29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<a name="signals"></a>
<h2>Signals</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdeclarativeexpression.html#valueChanged">valueChanged</a></b> ()</td></tr>
</table>
<ul>
<li class="fn">1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li class="fn">7 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li class="fn">8 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<!-- $$$QDeclarativeExpression-description -->
<div class="descr">
<h2>Detailed Description</h2>
<p>The QDeclarativeExpression class evaluates JavaScript in a QML context.</p>
<p>For example, given a file <tt>main.qml</tt> like this:</p>
<pre class="qml"> import QtQuick 1.0
<span class="type"><a href="qml-item.html">Item</a></span> {
<span class="name">width</span>: <span class="number">200</span>; <span class="name">height</span>: <span class="number">200</span>
}</pre>
<p>The following code evaluates a JavaScript expression in the context of the above QML:</p>
<pre class="cpp"> <span class="type"><a href="qdeclarativeengine.html">QDeclarativeEngine</a></span> <span class="operator">*</span>engine <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdeclarativeengine.html">QDeclarativeEngine</a></span>;
<span class="type"><a href="qdeclarativecomponent.html">QDeclarativeComponent</a></span> component(engine<span class="operator">,</span> <span class="type"><a href="qurl.html">QUrl</a></span><span class="operator">::</span>fromLocalFile(<span class="string">"main.qml"</span>));
<span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>myObject <span class="operator">=</span> component<span class="operator">.</span>create();
<span class="type">QDeclarativeExpression</span> <span class="operator">*</span>expr <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QDeclarativeExpression</span>(engine<span class="operator">-</span><span class="operator">></span>rootContext()<span class="operator">,</span> myObject<span class="operator">,</span> <span class="string">"width * 2"</span>);
<span class="type">int</span> result <span class="operator">=</span> expr<span class="operator">-</span><span class="operator">></span><a href="qdeclarativeexpression.html#evaluate">evaluate</a>()<span class="operator">.</span>toInt(); <span class="comment">// result = 400</span></pre>
</div>
<!-- @@@QDeclarativeExpression -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QDeclarativeExpression[overload1]$$$QDeclarativeExpression -->
<h3 class="fn"><a name="QDeclarativeExpression"></a>QDeclarativeExpression::<span class="name">QDeclarativeExpression</span> ()</h3>
<p>Create an invalid <a href="qdeclarativeexpression.html">QDeclarativeExpression</a>.</p>
<p>As the expression will not have an associated <a href="qdeclarativecontext.html">QDeclarativeContext</a>, this will be a null expression object and its value will always be an invalid <a href="qvariant.html">QVariant</a>.</p>
<!-- @@@QDeclarativeExpression -->
<!-- $$$QDeclarativeExpression$$$QDeclarativeExpressionQDeclarativeContext*QObject*constQString&QObject* -->
<h3 class="fn"><a name="QDeclarativeExpression-2"></a>QDeclarativeExpression::<span class="name">QDeclarativeExpression</span> ( <span class="type"><a href="qdeclarativecontext.html">QDeclarativeContext</a></span> * <i>ctxt</i>, <span class="type"><a href="qobject.html">QObject</a></span> * <i>scope</i>, const <span class="type"><a href="qstring.html">QString</a></span> & <i>expression</i>, <span class="type"><a href="qobject.html">QObject</a></span> * <i>parent</i> = 0 )</h3>
<p>Create a <a href="qdeclarativeexpression.html">QDeclarativeExpression</a> object that is a child of <i>parent</i>.</p>
<p>The <i>expression</i> JavaScript will be executed in the <i>ctxt</i> <a href="qdeclarativecontext.html">QDeclarativeContext</a>. If specified, the <i>scope</i> object's properties will also be in scope during the expression's execution.</p>
<!-- @@@QDeclarativeExpression -->
<!-- $$$~QDeclarativeExpression[overload1]$$$~QDeclarativeExpression -->
<h3 class="fn"><a name="dtor.QDeclarativeExpression"></a>QDeclarativeExpression::<span class="name">~QDeclarativeExpression</span> ()<tt> [virtual]</tt></h3>
<p>Destroy the <a href="qdeclarativeexpression.html">QDeclarativeExpression</a> instance.</p>
<!-- @@@~QDeclarativeExpression -->
<!-- $$$clearError[overload1]$$$clearError -->
<h3 class="fn"><a name="clearError"></a><span class="type">void</span> QDeclarativeExpression::<span class="name">clearError</span> ()</h3>
<p>Clear any expression errors. Calls to <a href="qdeclarativeexpression.html#hasError">hasError</a>() following this will return false.</p>
<p><b>See also </b><a href="qdeclarativeexpression.html#hasError">hasError</a>() and <a href="qdeclarativeexpression.html#error">error</a>().</p>
<!-- @@@clearError -->
<!-- $$$context[overload1]$$$context -->
<h3 class="fn"><a name="context"></a><span class="type"><a href="qdeclarativecontext.html">QDeclarativeContext</a></span> * QDeclarativeExpression::<span class="name">context</span> () const</h3>
<p>Returns the <a href="qdeclarativecontext.html">QDeclarativeContext</a> this expression is associated with, or 0 if there is no association or the <a href="qdeclarativecontext.html">QDeclarativeContext</a> has been destroyed.</p>
<!-- @@@context -->
<!-- $$$engine[overload1]$$$engine -->
<h3 class="fn"><a name="engine"></a><span class="type"><a href="qdeclarativeengine.html">QDeclarativeEngine</a></span> * QDeclarativeExpression::<span class="name">engine</span> () const</h3>
<p>Returns the <a href="qdeclarativeengine.html">QDeclarativeEngine</a> this expression is associated with, or 0 if there is no association or the <a href="qdeclarativeengine.html">QDeclarativeEngine</a> has been destroyed.</p>
<!-- @@@engine -->
<!-- $$$error[overload1]$$$error -->
<h3 class="fn"><a name="error"></a><span class="type"><a href="qdeclarativeerror.html">QDeclarativeError</a></span> QDeclarativeExpression::<span class="name">error</span> () const</h3>
<p>Return any error from the last call to <a href="qdeclarativeexpression.html#evaluate">evaluate</a>(). If there was no error, this returns an invalid <a href="qdeclarativeerror.html">QDeclarativeError</a> instance.</p>
<p><b>See also </b><a href="qdeclarativeexpression.html#hasError">hasError</a>() and <a href="qdeclarativeexpression.html#clearError">clearError</a>().</p>
<!-- @@@error -->
<!-- $$$evaluate[overload1]$$$evaluatebool* -->
<h3 class="fn"><a name="evaluate"></a><span class="type"><a href="qvariant.html">QVariant</a></span> QDeclarativeExpression::<span class="name">evaluate</span> ( <span class="type">bool</span> * <i>valueIsUndefined</i> = 0 )</h3>
<p>Evaulates the expression, returning the result of the evaluation, or an invalid <a href="qvariant.html">QVariant</a> if the expression is invalid or has an error.</p>
<p><i>valueIsUndefined</i> is set to true if the expression resulted in an undefined value.</p>
<p><b>See also </b><a href="qdeclarativeexpression.html#hasError">hasError</a>() and <a href="qdeclarativeexpression.html#error">error</a>().</p>
<!-- @@@evaluate -->
<!-- $$$expression[overload1]$$$expression -->
<h3 class="fn"><a name="expression"></a><span class="type"><a href="qstring.html">QString</a></span> QDeclarativeExpression::<span class="name">expression</span> () const</h3>
<p>Returns the expression string.</p>
<p><b>See also </b><a href="qdeclarativeexpression.html#setExpression">setExpression</a>().</p>
<!-- @@@expression -->
<!-- $$$hasError[overload1]$$$hasError -->
<h3 class="fn"><a name="hasError"></a><span class="type">bool</span> QDeclarativeExpression::<span class="name">hasError</span> () const</h3>
<p>Returns true if the last call to <a href="qdeclarativeexpression.html#evaluate">evaluate</a>() resulted in an error, otherwise false.</p>
<p><b>See also </b><a href="qdeclarativeexpression.html#error">error</a>() and <a href="qdeclarativeexpression.html#clearError">clearError</a>().</p>
<!-- @@@hasError -->
<!-- $$$lineNumber[overload1]$$$lineNumber -->
<h3 class="fn"><a name="lineNumber"></a><span class="type">int</span> QDeclarativeExpression::<span class="name">lineNumber</span> () const</h3>
<p>Returns the source file line number for this expression. The source location must have been previously set by calling <a href="qdeclarativeexpression.html#setSourceLocation">setSourceLocation</a>().</p>
<!-- @@@lineNumber -->
<!-- $$$notifyOnValueChanged[overload1]$$$notifyOnValueChanged -->
<h3 class="fn"><a name="notifyOnValueChanged"></a><span class="type">bool</span> QDeclarativeExpression::<span class="name">notifyOnValueChanged</span> () const</h3>
<p>Returns true if the <a href="qdeclarativeexpression.html#valueChanged">valueChanged</a>() signal is emitted when the expression's evaluated value changes.</p>
<p><b>See also </b><a href="qdeclarativeexpression.html#setNotifyOnValueChanged">setNotifyOnValueChanged</a>().</p>
<!-- @@@notifyOnValueChanged -->
<!-- $$$scopeObject[overload1]$$$scopeObject -->
<h3 class="fn"><a name="scopeObject"></a><span class="type"><a href="qobject.html">QObject</a></span> * QDeclarativeExpression::<span class="name">scopeObject</span> () const</h3>
<p>Returns the expression's scope object, if provided, otherwise 0.</p>
<p>In addition to data provided by the expression's <a href="qdeclarativecontext.html">QDeclarativeContext</a>, the scope object's properties are also in scope during the expression's evaluation.</p>
<!-- @@@scopeObject -->
<!-- $$$setExpression[overload1]$$$setExpressionconstQString& -->
<h3 class="fn"><a name="setExpression"></a><span class="type">void</span> QDeclarativeExpression::<span class="name">setExpression</span> ( const <span class="type"><a href="qstring.html">QString</a></span> & <i>expression</i> )</h3>
<p>Set the expression to <i>expression</i>.</p>
<p><b>See also </b><a href="qdeclarativeexpression.html#expression">expression</a>().</p>
<!-- @@@setExpression -->
<!-- $$$setNotifyOnValueChanged[overload1]$$$setNotifyOnValueChangedbool -->
<h3 class="fn"><a name="setNotifyOnValueChanged"></a><span class="type">void</span> QDeclarativeExpression::<span class="name">setNotifyOnValueChanged</span> ( <span class="type">bool</span> <i>notifyOnChange</i> )</h3>
<p>Sets whether the <a href="qdeclarativeexpression.html#valueChanged">valueChanged</a>() signal is emitted when the expression's evaluated value changes.</p>
<p>If <i>notifyOnChange</i> is true, the <a href="qdeclarativeexpression.html">QDeclarativeExpression</a> will monitor properties involved in the expression's evaluation, and emit <a href="qdeclarativeexpression.html#valueChanged">QDeclarativeExpression::valueChanged</a>() if they have changed. This allows an application to ensure that any value associated with the result of the expression remains up to date.</p>
<p>If <i>notifyOnChange</i> is false (default), the <a href="qdeclarativeexpression.html">QDeclarativeExpression</a> will not montitor properties involved in the expression's evaluation, and <a href="qdeclarativeexpression.html#valueChanged">QDeclarativeExpression::valueChanged</a>() will never be emitted. This is more efficient if an application wants a "one off" evaluation of the expression.</p>
<p><b>See also </b><a href="qdeclarativeexpression.html#notifyOnValueChanged">notifyOnValueChanged</a>().</p>
<!-- @@@setNotifyOnValueChanged -->
<!-- $$$setSourceLocation[overload1]$$$setSourceLocationconstQString&int -->
<h3 class="fn"><a name="setSourceLocation"></a><span class="type">void</span> QDeclarativeExpression::<span class="name">setSourceLocation</span> ( const <span class="type"><a href="qstring.html">QString</a></span> & <i>url</i>, <span class="type">int</span> <i>line</i> )</h3>
<p>Set the location of this expression to <i>line</i> of <i>url</i>. This information is used by the script engine.</p>
<!-- @@@setSourceLocation -->
<!-- $$$sourceFile[overload1]$$$sourceFile -->
<h3 class="fn"><a name="sourceFile"></a><span class="type"><a href="qstring.html">QString</a></span> QDeclarativeExpression::<span class="name">sourceFile</span> () const</h3>
<p>Returns the source file URL for this expression. The source location must have been previously set by calling <a href="qdeclarativeexpression.html#setSourceLocation">setSourceLocation</a>().</p>
<!-- @@@sourceFile -->
<!-- $$$valueChanged[overload1]$$$valueChanged -->
<h3 class="fn"><a name="valueChanged"></a><span class="type">void</span> QDeclarativeExpression::<span class="name">valueChanged</span> ()<tt> [signal]</tt></h3>
<p>Emitted each time the expression value changes from the last time it was evaluated. The expression must have been evaluated at least once (by calling <a href="qdeclarativeexpression.html#evaluate">QDeclarativeExpression::evaluate</a>()) before this signal will be emitted.</p>
<!-- @@@valueChanged -->
</div>
<div class="ft">
<span></span>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2012 Nokia Corporation and/or its
subsidiaries. Documentation contributions included herein are the copyrights of
their respective owners.</p>
<br />
<p>
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.</p>
<p>
Documentation sources may be obtained from <a href="http://www.qt-project.org">
www.qt-project.org</a>.</p>
<br />
<p>
Nokia, Qt and their respective logos are trademarks of Nokia Corporation
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. <a title="Privacy Policy"
href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>
|