File: qdeclarativeexpression.html

package info (click to toggle)
python-qt4 4.11.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 40,148 kB
  • ctags: 6,150
  • sloc: python: 125,936; cpp: 12,628; xml: 292; makefile: 259; php: 27; sh: 2
file content (132 lines) | stat: -rw-r--r-- 13,574 bytes parent folder | download
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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QDeclarativeExpression Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QDeclarativeExpression Class Reference<br /><sup><sup>[<a href="qtdeclarative.html">QtDeclarative</a> module]</sup></sup></h1><p>The QDeclarativeExpression class evaluates JavaScript in a QML
context. <a href="#details">More...</a></p>

<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qdeclarativeexpression.html#QDeclarativeExpression">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qdeclarativeexpression.html#QDeclarativeExpression-2">__init__</a></b> (<i>self</i>, QDeclarativeContext, QObject, QString, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qdeclarativeexpression.html#clearError">clearError</a></b> (<i>self</i>)</li><li><div class="fn" />QDeclarativeContext <b><a href="qdeclarativeexpression.html#context">context</a></b> (<i>self</i>)</li><li><div class="fn" />QDeclarativeEngine <b><a href="qdeclarativeexpression.html#engine">engine</a></b> (<i>self</i>)</li><li><div class="fn" />QDeclarativeError <b><a href="qdeclarativeexpression.html#error">error</a></b> (<i>self</i>)</li><li><div class="fn" />(QVariant, bool&#160;<i>valueIsUndefined</i>) <b><a href="qdeclarativeexpression.html#evaluate">evaluate</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qdeclarativeexpression.html#expression">expression</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qdeclarativeexpression.html#hasError">hasError</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qdeclarativeexpression.html#lineNumber">lineNumber</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qdeclarativeexpression.html#notifyOnValueChanged">notifyOnValueChanged</a></b> (<i>self</i>)</li><li><div class="fn" />QObject <b><a href="qdeclarativeexpression.html#scopeObject">scopeObject</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qdeclarativeexpression.html#setExpression">setExpression</a></b> (<i>self</i>, QString)</li><li><div class="fn" /><b><a href="qdeclarativeexpression.html#setNotifyOnValueChanged">setNotifyOnValueChanged</a></b> (<i>self</i>, bool)</li><li><div class="fn" /><b><a href="qdeclarativeexpression.html#setSourceLocation">setSourceLocation</a></b> (<i>self</i>, QString&#160;<i>fileName</i>, int&#160;<i>line</i>)</li><li><div class="fn" />QString <b><a href="qdeclarativeexpression.html#sourceFile">sourceFile</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qdeclarativeexpression.html#valueChanged">valueChanged</a></b> ()</li></ul><a name="details" /><hr /><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">&gt;</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">&gt;</span><a href="qdeclarativeexpression.html#evaluate">evaluate</a>()<span class="operator">.</span>toInt();  <span class="comment">// result = 400</span>
</pre><hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QDeclarativeExpression" />QDeclarativeExpression.__init__ (<i>self</i>)</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>


<h3 class="fn"><a name="QDeclarativeExpression-2" />QDeclarativeExpression.__init__ (<i>self</i>, <a href="qdeclarativecontext.html">QDeclarativeContext</a>, <a href="qobject.html">QObject</a>, QString, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><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>


<h3 class="fn"><a name="clearError" />QDeclarativeExpression.clearError (<i>self</i>)</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>


<h3 class="fn"><a name="context" /><a href="qdeclarativecontext.html">QDeclarativeContext</a> QDeclarativeExpression.context (<i>self</i>)</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>


<h3 class="fn"><a name="engine" /><a href="qdeclarativeengine.html">QDeclarativeEngine</a> QDeclarativeExpression.engine (<i>self</i>)</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>


<h3 class="fn"><a name="error" /><a href="qdeclarativeerror.html">QDeclarativeError</a> QDeclarativeExpression.error (<i>self</i>)</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>


<h3 class="fn"><a name="evaluate" />(QVariant, bool&#160;<i>valueIsUndefined</i>) QDeclarativeExpression.evaluate (<i>self</i>)</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>


<h3 class="fn"><a name="expression" />QString QDeclarativeExpression.expression (<i>self</i>)</h3><p>Returns the expression string.</p>
<p><b>See also</b> <a href="qdeclarativeexpression.html#setExpression">setExpression</a>().</p>


<h3 class="fn"><a name="hasError" />bool QDeclarativeExpression.hasError (<i>self</i>)</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>


<h3 class="fn"><a name="lineNumber" />int QDeclarativeExpression.lineNumber (<i>self</i>)</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>


<h3 class="fn"><a name="notifyOnValueChanged" />bool QDeclarativeExpression.notifyOnValueChanged (<i>self</i>)</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>


<h3 class="fn"><a name="scopeObject" /><a href="qobject.html">QObject</a> QDeclarativeExpression.scopeObject (<i>self</i>)</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>


<h3 class="fn"><a name="setExpression" />QDeclarativeExpression.setExpression (<i>self</i>, QString)</h3><p>Set the expression to <i>expression</i>.</p>
<p><b>See also</b> <a href="qdeclarativeexpression.html#expression">expression</a>().</p>


<h3 class="fn"><a name="setNotifyOnValueChanged" />QDeclarativeExpression.setNotifyOnValueChanged (<i>self</i>, bool)</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>


<h3 class="fn"><a name="setSourceLocation" />QDeclarativeExpression.setSourceLocation (<i>self</i>, QString&#160;<i>fileName</i>, int&#160;<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>


<h3 class="fn"><a name="sourceFile" />QString QDeclarativeExpression.sourceFile (<i>self</i>)</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>


<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="valueChanged" />void valueChanged ()</h3><p>This is the default overload of this signal.</p><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>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.11.4 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qt.io">The Qt Company</a> 2015</td><td align="right" width="25%">Qt&#160;4.8.7</td></tr></table></div></address></body></html>