summaryrefslogtreecommitdiffstats
path: root/qtscriptclassic/doc/html/qscriptengine-obsolete.html
blob: 1a07db3c98b1ad4ea956c0f51fcba45eefad66c8 (plain)
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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- qscriptengine.cpp -->
<head>
  <title>Obsolete Members for QScriptEngine</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="57" height="67" border="0" /></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a></td>
</tr></table><h1 class="title">Obsolete Members for QScriptEngine</h1>
<p><b>The following class members are obsolete.</b> They are provided to keep old source code working. We strongly advise against using them in new code.</p>
<p><ul><li><a href="qscriptengine.html">QScriptEngine class reference</a></li></ul></p>
<h2>Public Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qscriptengine-obsolete.html#canEvaluate">canEvaluate</a></b> ( const QString &amp; <i>program</i> ) const&nbsp;&nbsp;<tt> (obsolete)</tt></td></tr>
</table>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="canEvaluate"></a>bool QScriptEngine::canEvaluate ( const <a href="http://qt.nokia.com/doc/4.6/qstring.html">QString</a> &amp; <i>program</i> ) const</h3>
<p>Returns true if <i>program</i> can be evaluated; i.e&#x2e; the code is sufficient to determine whether it appears to be a syntactically correct program, or contains a syntax error.</p>
<p>This function returns false if <i>program</i> is incomplete; i.e&#x2e; the input is syntactically correct up to the point where the input is terminated.</p>
<p>Note that this function only does a static check of <i>program</i>; e.g&#x2e; it does not check whether references to variables are valid, and so on.</p>
<p>A typical usage of canEvaluate() is to implement an interactive interpreter for <a href="http://qt.nokia.com/doc/4.6/qtscript.html">QtScript</a>. The user is repeatedly queried for individual lines of code; the lines are concatened internally, and only when canEvaluate() returns true for the resulting program is it passed to <a href="qscriptengine.html#evaluate">evaluate</a>().</p>
<p>The following are some examples to illustrate the behavior of canEvaluate(). (Note that all example inputs are assumed to have an explicit newline as their last character, since otherwise the <a href="http://qt.nokia.com/doc/4.6/qtscript.html">QtScript</a> parser would automatically insert a semi-colon character at the end of the input, and this could cause canEvaluate() to produce different results.)</p>
<p>Given the input</p>
<pre> if (hello &amp;&amp; world)
     print(&quot;hello world&quot;);</pre>
<p>canEvaluate() will return true, since the program appears to be complete.</p>
<p>Given the input</p>
<pre> if (hello &amp;&amp;</pre>
<p>canEvaluate() will return false, since the if-statement is not complete, but is syntactically correct so far.</p>
<p>Given the input</p>
<pre> 0 = 0</pre>
<p>canEvaluate() will return true, but <a href="qscriptengine.html#evaluate">evaluate</a>() will throw a SyntaxError given the same input.</p>
<p>Given the input</p>
<pre> ./test.js</pre>
<p>canEvaluate() will return true, even though the code is clearly not syntactically valid <a href="http://qt.nokia.com/doc/4.6/qtscript.html">QtScript</a> code. <a href="qscriptengine.html#evaluate">evaluate</a>() will throw a SyntaxError when this code is evaluated.</p>
<p>Given the input</p>
<pre> foo[&quot;bar&quot;]</pre>
<p>canEvaluate() will return true, but <a href="qscriptengine.html#evaluate">evaluate</a>() will throw a ReferenceError if <tt>foo</tt> is not defined in the script environment.</p>
<p>See also <a href="qscriptengine.html#evaluate">evaluate</a>() and <a href="qscriptengine.html#checkSyntax">checkSyntax</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="40%" align="center"><a href="http://qt.nokia.com/doc/trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt Solutions</div></td>
</tr></table></div></address></body>
</html>