<?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>QScriptEngine 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">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QScriptEngine Class Reference<br /><sup><sup>[<a href="qtscript.html">QtScript</a> module]</sup></sup></h1><p>The QScriptEngine class provides an environment for evaluating Qt Script code. <a href="#details">More...</a></p> <p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qscriptengine.html#QObjectWrapOption-enum">QObjectWrapOption</a></b> { ExcludeChildObjects, ExcludeSuperClassMethods, ExcludeSuperClassProperties, AutoCreateDynamicProperties, ..., ExcludeSlots }</li><li><div class="fn" />class <b><a href="qscriptengine-qobjectwrapoptions.html">QObjectWrapOptions</a></b></li><li><div class="fn" />enum <b><a href="qscriptengine.html#ValueOwnership-enum">ValueOwnership</a></b> { QtOwnership, ScriptOwnership, AutoOwnership }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qscriptengine.html#QScriptEngine">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#QScriptEngine-2">__init__</a></b> (<i>self</i>, QObject <i>parent</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#abortEvaluation">abortEvaluation</a></b> (<i>self</i>, QScriptValue <i>result</i> = QScriptValue())</li><li><div class="fn" />QScriptEngineAgent <b><a href="qscriptengine.html#agent">agent</a></b> (<i>self</i>)</li><li><div class="fn" />QStringList <b><a href="qscriptengine.html#availableExtensions">availableExtensions</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qscriptengine.html#canEvaluate">canEvaluate</a></b> (<i>self</i>, QString <i>program</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#clearExceptions">clearExceptions</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#collectGarbage">collectGarbage</a></b> (<i>self</i>)</li><li><div class="fn" />QScriptContext <b><a href="qscriptengine.html#currentContext">currentContext</a></b> (<i>self</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#defaultPrototype">defaultPrototype</a></b> (<i>self</i>, int <i>metaTypeId</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#evaluate">evaluate</a></b> (<i>self</i>, QString <i>program</i>, QString <i>fileName</i> = QString(), int <i>lineNumber</i> = 1)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#globalObject">globalObject</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qscriptengine.html#hasUncaughtException">hasUncaughtException</a></b> (<i>self</i>)</li><li><div class="fn" />QStringList <b><a href="qscriptengine.html#importedExtensions">importedExtensions</a></b> (<i>self</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#importExtension">importExtension</a></b> (<i>self</i>, QString <i>extension</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#installTranslatorFunctions">installTranslatorFunctions</a></b> (<i>self</i>, QScriptValue <i>object</i> = QScriptValue())</li><li><div class="fn" />bool <b><a href="qscriptengine.html#isEvaluating">isEvaluating</a></b> (<i>self</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newArray">newArray</a></b> (<i>self</i>, int <i>length</i> = 0)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newDate">newDate</a></b> (<i>self</i>, float <i>value</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newDate-2">newDate</a></b> (<i>self</i>, QDateTime <i>value</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newFunction">newFunction</a></b> (<i>self</i>, callable <i>signature</i>, int <i>length</i> = 0)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newFunction-2">newFunction</a></b> (<i>self</i>, callable <i>signature</i>, QScriptValue <i>prototype</i>, int <i>length</i> = 0)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newObject">newObject</a></b> (<i>self</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newObject-2">newObject</a></b> (<i>self</i>, QScriptClass <i>scriptClass</i>, QScriptValue <i>data</i> = QScriptValue())</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newQMetaObject">newQMetaObject</a></b> (<i>self</i>, QMetaObject <i>metaObject</i>, QScriptValue <i>ctor</i> = QScriptValue())</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newQObject">newQObject</a></b> (<i>self</i>, QObject <i>object</i>, ValueOwnership <i>ownership</i> = QScriptEngine.QtOwnership, QObjectWrapOptions <i>options</i> = 0)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newQObject-2">newQObject</a></b> (<i>self</i>, QScriptValue <i>scriptObject</i>, QObject <i>qtObject</i>, ValueOwnership <i>ownership</i> = QScriptEngine.QtOwnership, QObjectWrapOptions <i>options</i> = 0)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newRegExp">newRegExp</a></b> (<i>self</i>, QRegExp <i>regexp</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newRegExp-2">newRegExp</a></b> (<i>self</i>, QString <i>pattern</i>, QString <i>flags</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newVariant">newVariant</a></b> (<i>self</i>, QVariant <i>value</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#newVariant-2">newVariant</a></b> (<i>self</i>, QScriptValue <i>object</i>, QVariant <i>value</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#nullValue">nullValue</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#popContext">popContext</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qscriptengine.html#processEventsInterval">processEventsInterval</a></b> (<i>self</i>)</li><li><div class="fn" />QScriptContext <b><a href="qscriptengine.html#pushContext">pushContext</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#reportAdditionalMemoryCost">reportAdditionalMemoryCost</a></b> (<i>self</i>, int <i>size</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#setAgent">setAgent</a></b> (<i>self</i>, QScriptEngineAgent <i>agent</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#setDefaultPrototype">setDefaultPrototype</a></b> (<i>self</i>, int <i>metaTypeId</i>, QScriptValue <i>prototype</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#setGlobalObject">setGlobalObject</a></b> (<i>self</i>, QScriptValue <i>object</i>)</li><li><div class="fn" /><b><a href="qscriptengine.html#setProcessEventsInterval">setProcessEventsInterval</a></b> (<i>self</i>, int <i>interval</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#toObject">toObject</a></b> (<i>self</i>, QScriptValue <i>value</i>)</li><li><div class="fn" />QScriptString <b><a href="qscriptengine.html#toStringHandle">toStringHandle</a></b> (<i>self</i>, QString <i>str</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#uncaughtException">uncaughtException</a></b> (<i>self</i>)</li><li><div class="fn" />QStringList <b><a href="qscriptengine.html#uncaughtExceptionBacktrace">uncaughtExceptionBacktrace</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qscriptengine.html#uncaughtExceptionLineNumber">uncaughtExceptionLineNumber</a></b> (<i>self</i>)</li><li><div class="fn" />QScriptValue <b><a href="qscriptengine.html#undefinedValue">undefinedValue</a></b> (<i>self</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QScriptSyntaxCheckResult <b><a href="qscriptengine.html#checkSyntax">checkSyntax</a></b> (QString <i>program</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qscriptengine.html#signalHandlerException">signalHandlerException</a></b> (const QScriptValue&)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QScriptEngine class provides an environment for evaluating Qt Script code.</p> <p>See the <a href="qtscript.html">QtScript</a> documentation for information about the Qt Script language, and how to get started with scripting your C++ application.</p> <a id="evaluating-scripts" name="evaluating-scripts" /> <h3>Evaluating Scripts</h3> <p>Use <a href="qscriptengine.html#evaluate">evaluate</a>() to evaluate script code; this is the C++ equivalent of the built-in script function <tt>eval()</tt>.</p> <pre class="cpp"> <span class="type">QScriptEngine</span> myEngine; <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> three <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qscriptengine.html#evaluate">evaluate</a>(<span class="string">"1 + 2"</span>); </pre> <p><a href="qscriptengine.html#evaluate">evaluate</a>() returns a <a href="qscriptvalue.html">QScriptValue</a> that holds the result of the evaluation. The <a href="qscriptvalue.html">QScriptValue</a> class provides functions for converting the result to various C++ types (e.g. <a href="qscriptvalue.html#toString">QScriptValue.toString</a>() and <a href="qscriptvalue.html#toNumber">QScriptValue.toNumber</a>()).</p> <p>The following code snippet shows how a script function can be defined and then invoked from C++ using <a href="qscriptvalue.html#call">QScriptValue.call</a>():</p> <pre class="cpp"> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> fun <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qscriptengine.html#evaluate">evaluate</a>(<span class="string">"(function(a, b) { return a + b; })"</span>); <span class="type">QScriptValueList</span> args; args <span class="operator"><</span><span class="operator"><</span> <span class="number">1</span> <span class="operator"><</span><span class="operator"><</span> <span class="number">2</span>; <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> threeAgain <span class="operator">=</span> fun<span class="operator">.</span>call(<span class="type"><a href="qscriptvalue.html">QScriptValue</a></span>()<span class="operator">,</span> args); </pre> <p>As can be seen from the above snippets, a script is provided to the engine in the form of a string. One common way of loading scripts is by reading the contents of a file and passing it to <a href="qscriptengine.html#evaluate">evaluate</a>():</p> <pre class="cpp"> <span class="type"><a href="qstring.html">QString</a></span> fileName <span class="operator">=</span> <span class="string">"helloworld.qs"</span>; <span class="type"><a href="qfile.html">QFile</a></span> scriptFile(fileName); <span class="keyword">if</span> (<span class="operator">!</span>scriptFile<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly)) <span class="comment">// handle error</span> <span class="type"><a href="qtextstream.html">QTextStream</a></span> stream(<span class="operator">&</span>scriptFile); <span class="type"><a href="qstring.html">QString</a></span> contents <span class="operator">=</span> stream<span class="operator">.</span>readAll(); scriptFile<span class="operator">.</span>close(); myEngine<span class="operator">.</span><a href="qscriptengine.html#evaluate">evaluate</a>(contents<span class="operator">,</span> fileName); </pre> <p>Here we pass the name of the file as the second argument to <a href="qscriptengine.html#evaluate">evaluate</a>(). This does not affect evaluation in any way; the second argument is a general-purpose string that is used to identify the script for debugging purposes (for example, our filename will now show up in any <a href="qscriptengine.html#uncaughtExceptionBacktrace">uncaughtExceptionBacktrace</a>() involving the script).</p> <a id="engine-configuration" name="engine-configuration" /> <h3>Engine Configuration</h3> <p>The <a href="qscriptengine.html#globalObject">globalObject</a>() function returns the <b>Global Object</b> associated with the script engine. Properties of the Global Object are accessible from any script code (i.e. they are global variables). Typically, before evaluating "user" scripts, you will want to configure a script engine by adding one or more properties to the Global Object:</p> <pre class="cpp"> myEngine<span class="operator">.</span><a href="qscriptengine.html#globalObject">globalObject</a>()<span class="operator">.</span><a href="qobject.html#setProperty">setProperty</a>(<span class="string">"myNumber"</span><span class="operator">,</span> <span class="number">123</span>); <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> myNumberPlusOne <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qscriptengine.html#evaluate">evaluate</a>(<span class="string">"myNumber + 1"</span>); </pre> <p>Adding custom properties to the scripting environment is one of the standard means of providing a scripting API that is specific to your application. Usually these custom properties are objects created by the <a href="qscriptengine.html#newQObject">newQObject</a>() or <a href="qscriptengine.html#newObject">newObject</a>() functions, or constructor functions created by <a href="qscriptengine.html#newFunction">newFunction</a>().</p> <a id="script-exceptions" name="script-exceptions" /> <h3>Script Exceptions</h3> <p><a href="qscriptengine.html#evaluate">evaluate</a>() can throw a script exception (e.g. due to a syntax error); in that case, the return value is the value that was thrown (typically an <tt>Error</tt> object). You can check whether the evaluation caused an exception by calling <a href="qscriptengine.html#hasUncaughtException">hasUncaughtException</a>(). In that case, you can call toString() on the error object to obtain an error message. The current uncaught exception is also available through <a href="qscriptengine.html#uncaughtException">uncaughtException</a>(). Calling <a href="qscriptengine.html#clearExceptions">clearExceptions</a>() will cause any uncaught exceptions to be cleared.</p> <pre class="cpp"> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> result <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qscriptengine.html#evaluate">evaluate</a>(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>); <span class="keyword">if</span> (myEngine<span class="operator">.</span>hasUncaughtException()) { <span class="type">int</span> line <span class="operator">=</span> myEngine<span class="operator">.</span>uncaughtExceptionLineNumber(); <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"uncaught exception at line"</span> <span class="operator"><</span><span class="operator"><</span> line <span class="operator"><</span><span class="operator"><</span> <span class="string">":"</span> <span class="operator"><</span><span class="operator"><</span> result<span class="operator">.</span>toString(); } </pre> <p>The <a href="qscriptengine.html#checkSyntax">checkSyntax</a>() function can be used to determine whether code can be usefully passed to <a href="qscriptengine.html#evaluate">evaluate</a>().</p> <a id="script-object-creation" name="script-object-creation" /> <h3>Script Object Creation</h3> <p>Use <a href="qscriptengine.html#newObject">newObject</a>() to create a standard Qt Script object; this is the C++ equivalent of the script statement <tt>new Object()</tt>. You can use the object-specific functionality in <a href="qscriptvalue.html">QScriptValue</a> to manipulate the script object (e.g. <a href="qscriptvalue.html#setProperty">QScriptValue.setProperty</a>()). Similarly, use <a href="qscriptengine.html#newArray">newArray</a>() to create a Qt Script array object. Use <a href="qscriptengine.html#newDate">newDate</a>() to create a <tt>Date</tt> object, and <a href="qscriptengine.html#newRegExp">newRegExp</a>() to create a <tt>RegExp</tt> object.</p> <a id="qobject-integration" name="qobject-integration" /> <h3>QObject Integration</h3> <p>Use <a href="qscriptengine.html#newQObject">newQObject</a>() to wrap a <a href="qobject.html">QObject</a> (or subclass) pointer. <a href="qscriptengine.html#newQObject">newQObject</a>() returns a proxy script object; properties, children, and signals and slots of the <a href="qobject.html">QObject</a> are available as properties of the proxy object. No binding code is needed because it is done dynamically using the Qt meta object system.</p> <pre class="cpp"> <span class="type"><a href="qpushbutton.html">QPushButton</a></span> button; <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> scriptButton <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qscriptengine.html#newQObject">newQObject</a>(<span class="operator">&</span>button); myEngine<span class="operator">.</span><a href="qscriptengine.html#globalObject">globalObject</a>()<span class="operator">.</span><a href="qobject.html#setProperty">setProperty</a>(<span class="string">"button"</span><span class="operator">,</span> scriptButton); myEngine<span class="operator">.</span><a href="qscriptengine.html#evaluate">evaluate</a>(<span class="string">"button.checkable = true"</span>); <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> scriptButton<span class="operator">.</span><a href="qobject.html#property">property</a>(<span class="string">"checkable"</span>)<span class="operator">.</span>toBoolean(); scriptButton<span class="operator">.</span><a href="qobject.html#property">property</a>(<span class="string">"show"</span>)<span class="operator">.</span>call(); <span class="comment">// call the show() slot</span> </pre> <p>Use <a href="qscriptengine.html#qScriptConnect">qScriptConnect</a>() to connect a C++ signal to a script function; this is the Qt Script equivalent of <a href="qobject.html#connect">QObject.connect</a>(). When a script function is invoked in response to a C++ signal, it can cause a script exception; you can connect to the <a href="qscriptengine.html#signalHandlerException">signalHandlerException</a>() signal to catch such an exception.</p> <p>Use <a href="qscriptengine.html#newQMetaObject">newQMetaObject</a>() to wrap a <a href="qmetaobject.html">QMetaObject</a>; this gives you a "script representation" of a <a href="qobject.html">QObject</a>-based class. <a href="qscriptengine.html#newQMetaObject">newQMetaObject</a>() returns a proxy script object; enum values of the class are available as properties of the proxy object. You can also specify a function that will be used to construct objects of the class (e.g. when the constructor is invoked from a script). For classes that have a "standard" Qt constructor, Qt Script can provide a default script constructor for you; see <a href="qscriptengine.html#scriptValueFromQMetaObject">scriptValueFromQMetaObject</a>().</p> <p>For more information about <a href="qobject.html">QObject</a> integration, see <a href="scripting.html">Making Applications Scriptable</a></p> <a id="support-for-custom-c-types" name="support-for-custom-c-types" /> <h3>Support for Custom C++ Types</h3> <p>Use <a href="qscriptengine.html#newVariant">newVariant</a>() to wrap a <a href="qvariant.html">QVariant</a>. This can be used to store values of custom (non-<a href="qobject.html">QObject</a>) C++ types that have been registered with the Qt meta-type system. To make such types scriptable, you typically associate a prototype (delegate) object with the C++ type by calling <a href="qscriptengine.html#setDefaultPrototype">setDefaultPrototype</a>(); the prototype object defines the scripting API for the C++ type. Unlike the <a href="qobject.html">QObject</a> integration, there is no automatic binding possible here; i.e. you have to create the scripting API yourself, for example by using the <a href="qscriptable.html">QScriptable</a> class.</p> <p>Use <a href="qscriptengine.html#fromScriptValue">fromScriptValue</a>() to cast from a <a href="qscriptvalue.html">QScriptValue</a> to another type, and <a href="qscriptengine.html#toScriptValue">toScriptValue</a>() to create a <a href="qscriptvalue.html">QScriptValue</a> from another value. You can specify how the conversion of C++ types is to be performed with <a href="qscriptengine.html#qScriptRegisterMetaType">qScriptRegisterMetaType</a>() and <a href="qscriptengine.html#qScriptRegisterSequenceMetaType">qScriptRegisterSequenceMetaType</a>(). By default, Qt Script will use <a href="qvariant.html">QVariant</a> to store values of custom types.</p> <a id="importing-extensions" name="importing-extensions" /> <h3>Importing Extensions</h3> <p>Use <a href="qscriptengine.html#importExtension">importExtension</a>() to import plugin-based extensions into the engine. Call <a href="qscriptengine.html#availableExtensions">availableExtensions</a>() to obtain a list naming all the available extensions, and <a href="qscriptengine.html#importedExtensions">importedExtensions</a>() to obtain a list naming only those extensions that have been imported.</p> <p>Call <a href="qscriptengine.html#pushContext">pushContext</a>() to open up a new variable scope, and <a href="qscriptengine.html#popContext">popContext</a>() to close the current scope. This is useful if you are implementing an extension that evaluates script code containing temporary variable definitions (e.g. <tt>var foo = 123;</tt>) that are safe to discard when evaluation has completed.</p> <a id="native-functions" name="native-functions" /> <h3>Native Functions</h3> <p>Use <a href="qscriptengine.html#newFunction">newFunction</a>() to wrap native (C++) functions, including constructors for your own custom types, so that these can be invoked from script code. Such functions must have the signature <a href="qscriptengine.html#FunctionSignature-typedef">QScriptEngine.FunctionSignature</a>. You may then pass the function as argument to <a href="qscriptengine.html#newFunction">newFunction</a>(). Here is an example of a function that returns the sum of its first two arguments:</p> <pre class="cpp"> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> myAdd(<span class="type"><a href="qscriptcontext.html">QScriptContext</a></span> <span class="operator">*</span>context<span class="operator">,</span> <span class="type">QScriptEngine</span> <span class="operator">*</span>engine) { <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> a <span class="operator">=</span> context<span class="operator">-</span><span class="operator">></span>argument(<span class="number">0</span>); <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> b <span class="operator">=</span> context<span class="operator">-</span><span class="operator">></span>argument(<span class="number">1</span>); <span class="keyword">return</span> a<span class="operator">.</span>toNumber() <span class="operator">+</span> b<span class="operator">.</span>toNumber(); } </pre> <p>To expose this function to script code, you can set it as a property of the Global Object:</p> <pre class="cpp"> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> fun <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qscriptengine.html#newFunction">newFunction</a>(myAdd); myEngine<span class="operator">.</span><a href="qscriptengine.html#globalObject">globalObject</a>()<span class="operator">.</span><a href="qobject.html#setProperty">setProperty</a>(<span class="string">"myAdd"</span><span class="operator">,</span> fun); </pre> <p>Once this is done, script code can call your function in the exact same manner as a "normal" script function:</p> <pre class="cpp"> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> result <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qscriptengine.html#evaluate">evaluate</a>(<span class="string">"myAdd(myNumber, 1)"</span>); </pre> <a id="long-running-scripts" name="long-running-scripts" /> <h3>Long-running Scripts</h3> <p>If you need to evaluate possibly long-running scripts from the main (GUI) thread, you should first call <a href="qscriptengine.html#setProcessEventsInterval">setProcessEventsInterval</a>() to make sure that the GUI stays responsive. You can abort a currently running script by calling <a href="qscriptengine.html#abortEvaluation">abortEvaluation</a>(). You can determine whether an engine is currently running a script by calling <a href="qscriptengine.html#isEvaluating">isEvaluating</a>().</p> <a id="garbage-collection" name="garbage-collection" /> <h3>Garbage Collection</h3> <p>Qt Script objects may be garbage collected when they are no longer referenced. There is no guarantee as to when automatic garbage collection will take place.</p> <p>The <a href="qscriptengine.html#collectGarbage">collectGarbage</a>() function can be called to explicitly request garbage collection.</p> <p>The <a href="qscriptengine.html#reportAdditionalMemoryCost">reportAdditionalMemoryCost</a>() function can be called to indicate that a Qt Script object occupies memory that isn't managed by the scripting environment. Reporting the additional cost makes it more likely that the garbage collector will be triggered. This can be useful, for example, when many custom, native Qt Script objects are allocated.</p> <a id="core-debugging-tracing-facilities" name="core-debugging-tracing-facilities" /> <h3>Core Debugging/Tracing Facilities</h3> <p>Since Qt 4.4, you can be notified of events pertaining to script execution (e.g. script function calls and statement execution) through the <a href="qscriptengineagent.html">QScriptEngineAgent</a> interface; see the <a href="qscriptengine.html#setAgent">setAgent</a>() function. This can be used to implement debugging and profiling of a QScriptEngine.</p> <hr /><h2>Type Documentation</h2><h3 class="fn"><a name="QObjectWrapOption-enum" />QScriptEngine.QObjectWrapOption</h3><p>These flags specify options when wrapping a <a href="qobject.html">QObject</a> pointer with <a href="qscriptengine.html#newQObject">newQObject</a>().</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"> <tt>QScriptEngine.ExcludeChildObjects</tt></td> <td class="topAlign"><tt>0x0001</tt></td> <td class="topAlign">The script object will not expose child objects as properties.</td> </tr> <tr> <td class="topAlign"> <tt>QScriptEngine.ExcludeSuperClassMethods</tt></td> <td class="topAlign"><tt>0x0002</tt></td> <td class="topAlign">The script object will not expose signals and slots inherited from the superclass.</td> </tr> <tr> <td class="topAlign"> <tt>QScriptEngine.ExcludeSuperClassProperties</tt></td> <td class="topAlign"><tt>0x0004</tt></td> <td class="topAlign">The script object will not expose properties inherited from the superclass.</td> </tr> <tr> <td class="topAlign"> <tt>QScriptEngine.ExcludeSuperClassContents</tt></td> <td class="topAlign"><tt>0x0006</tt></td> <td class="topAlign">Shorthand form for ExcludeSuperClassMethods | ExcludeSuperClassProperties</td> </tr> <tr> <td class="topAlign"> <tt>QScriptEngine.ExcludeDeleteLater</tt></td> <td class="topAlign"><tt>0x0010</tt></td> <td class="topAlign">The script object will not expose the <a href="qobject.html#deleteLater">QObject.deleteLater</a>() slot.</td> </tr> <tr> <td class="topAlign"><tt>QScriptEngine.ExcludeSlots</tt></td> <td class="topAlign"><tt>0x0020</tt></td> <td class="topAlign">The script object will not expose the <a href="qobject.html">QObject</a>'s slots.</td> </tr> <tr> <td class="topAlign"> <tt>QScriptEngine.AutoCreateDynamicProperties</tt></td> <td class="topAlign"><tt>0x0100</tt></td> <td class="topAlign">Properties that don't already exist in the <a href="qobject.html">QObject</a> will be created as dynamic properties of that object, rather than as properties of the script object.</td> </tr> <tr> <td class="topAlign"> <tt>QScriptEngine.PreferExistingWrapperObject</tt></td> <td class="topAlign"><tt>0x0200</tt></td> <td class="topAlign">If a wrapper object with the requested configuration already exists, return that object.</td> </tr> <tr> <td class="topAlign"> <tt>QScriptEngine.SkipMethodsInEnumeration</tt></td> <td class="topAlign"><tt>0x0008</tt></td> <td class="topAlign">Don't include methods (signals and slots) when enumerating the object's properties.</td> </tr> </table> <p>The QObjectWrapOptions type is a typedef for <a href="qflags.html">QFlags</a><QObjectWrapOption>. It stores an OR combination of QObjectWrapOption values.</p> <h3 class="fn"><a name="ValueOwnership-enum" />QScriptEngine.ValueOwnership</h3><p>This enum specifies the ownership when wrapping a C++ value, e.g. by using <a href="qscriptengine.html#newQObject">newQObject</a>().</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QScriptEngine.QtOwnership</tt></td> <td class="topAlign"><tt>0</tt></td> <td class="topAlign">The standard Qt ownership rules apply, i.e. the associated object will never be explicitly deleted by the script engine. This is the default. (<a href="qobject.html">QObject</a> ownership is explained in <a href="objecttrees.html">Object Trees & Ownership</a>.)</td> </tr> <tr> <td class="topAlign"><tt>QScriptEngine.ScriptOwnership</tt></td> <td class="topAlign"><tt>1</tt></td> <td class="topAlign">The value is owned by the script environment. The associated data will be deleted when appropriate (i.e. after the garbage collector has discovered that there are no more live references to the value).</td> </tr> <tr> <td class="topAlign"><tt>QScriptEngine.AutoOwnership</tt></td> <td class="topAlign"><tt>2</tt></td> <td class="topAlign">If the associated object has a parent, the Qt ownership rules apply (QtOwnership); otherwise, the object is owned by the script environment (ScriptOwnership).</td> </tr> </table> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QScriptEngine" />QScriptEngine.__init__ (<i>self</i>)</h3><p>Constructs a <a href="qscriptengine.html">QScriptEngine</a> object.</p> <p>The <a href="qscriptengine.html#globalObject">globalObject</a>() is initialized to have properties as described in <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm"> ECMA-262</a>, Section 15.1.</p> <h3 class="fn"><a name="QScriptEngine-2" />QScriptEngine.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qscriptengine.html">QScriptEngine</a> object with the given <i>parent</i>.</p> <p>The <a href="qscriptengine.html#globalObject">globalObject</a>() is initialized to have properties as described in <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm"> ECMA-262</a>, Section 15.1.</p> <h3 class="fn"><a name="abortEvaluation" />QScriptEngine.abortEvaluation (<i>self</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>result</i> = QScriptValue())</h3><p>Aborts any script evaluation currently taking place in this engine. The given <i>result</i> is passed back as the result of the evaluation (i.e. it is returned from the call to <a href="qscriptengine.html#evaluate">evaluate</a>() being aborted).</p> <p>If the engine isn't evaluating a script (i.e. <a href="qscriptengine.html#isEvaluating">isEvaluating</a>() returns false), this function does nothing.</p> <p>Call this function if you need to abort a running script for some reason, e.g. when you have detected that the script has been running for several seconds without completing.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#evaluate">evaluate</a>(), <a href="qscriptengine.html#isEvaluating">isEvaluating</a>(), and <a href="qscriptengine.html#setProcessEventsInterval">setProcessEventsInterval</a>().</p> <h3 class="fn"><a name="agent" /><a href="qscriptengineagent.html">QScriptEngineAgent</a> QScriptEngine.agent (<i>self</i>)</h3><p>Returns the agent currently installed on this engine, or 0 if no agent is installed.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#setAgent">setAgent</a>().</p> <h3 class="fn"><a name="availableExtensions" />QStringList QScriptEngine.availableExtensions (<i>self</i>)</h3><p>Returns a list naming the available extensions that can be imported using the <a href="qscriptengine.html#importExtension">importExtension</a>() function. This list includes extensions that have been imported.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#importExtension">importExtension</a>() and <a href="qscriptengine.html#importedExtensions">importedExtensions</a>().</p> <h3 class="fn"><a name="canEvaluate" />bool QScriptEngine.canEvaluate (<i>self</i>, QString <i>program</i>)</h3><h3 class="fn"><a name="checkSyntax" /><a href="qscriptsyntaxcheckresult.html">QScriptSyntaxCheckResult</a> QScriptEngine.checkSyntax (QString <i>program</i>)</h3><p>Checks the syntax of the given <i>program</i>. Returns a <a href="qscriptsyntaxcheckresult.html">QScriptSyntaxCheckResult</a> object that contains the result of the check.</p> <p>This function was introduced in Qt 4.5.</p> <h3 class="fn"><a name="clearExceptions" />QScriptEngine.clearExceptions (<i>self</i>)</h3><p>Clears any uncaught exceptions in this engine.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#hasUncaughtException">hasUncaughtException</a>().</p> <h3 class="fn"><a name="collectGarbage" />QScriptEngine.collectGarbage (<i>self</i>)</h3><p>Runs the garbage collector.</p> <p>The garbage collector will attempt to reclaim memory by locating and disposing of objects that are no longer reachable in the script environment.</p> <p>Normally you don't need to call this function; the garbage collector will automatically be invoked when the <a href="qscriptengine.html">QScriptEngine</a> decides that it's wise to do so (i.e. when a certain number of new objects have been created). However, you can call this function to explicitly request that garbage collection should be performed as soon as possible.</p> <p><b>See also</b> <a href="qscriptengine.html#reportAdditionalMemoryCost">reportAdditionalMemoryCost</a>().</p> <h3 class="fn"><a name="currentContext" /><a href="qscriptcontext.html">QScriptContext</a> QScriptEngine.currentContext (<i>self</i>)</h3><p>Returns the current context.</p> <p>The current context is typically accessed to retrieve the arguments and `this' object in native functions; for convenience, it is available as the first argument in <a href="qscriptengine.html#FunctionSignature-typedef">QScriptEngine.FunctionSignature</a>.</p> <h3 class="fn"><a name="defaultPrototype" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.defaultPrototype (<i>self</i>, int <i>metaTypeId</i>)</h3><p>Returns the default prototype associated with the given <i>metaTypeId</i>, or an invalid <a href="qscriptvalue.html">QScriptValue</a> if no default prototype has been set.</p> <p><b>See also</b> <a href="qscriptengine.html#setDefaultPrototype">setDefaultPrototype</a>().</p> <h3 class="fn"><a name="evaluate" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.evaluate (<i>self</i>, QString <i>program</i>, QString <i>fileName</i> = QString(), int <i>lineNumber</i> = 1)</h3><p>Evaluates <i>program</i>, using <i>lineNumber</i> as the base line number, and returns the result of the evaluation.</p> <p>The script code will be evaluated in the current context.</p> <p>The evaluation of <i>program</i> can cause an exception in the engine; in this case the return value will be the exception that was thrown (typically an <tt>Error</tt> object). You can call <a href="qscriptengine.html#hasUncaughtException">hasUncaughtException</a>() to determine if an exception occurred in the last call to evaluate().</p> <p><i>lineNumber</i> is used to specify a starting line number for <i>program</i>; line number information reported by the engine that pertain to this evaluation (e.g. <a href="qscriptengine.html#uncaughtExceptionLineNumber">uncaughtExceptionLineNumber</a>()) will be based on this argument. For example, if <i>program</i> consists of two lines of code, and the statement on the second line causes a script exception, <a href="qscriptengine.html#uncaughtExceptionLineNumber">uncaughtExceptionLineNumber</a>() would return the given <i>lineNumber</i> plus one. When no starting line number is specified, line numbers will be 1-based.</p> <p><i>fileName</i> is used for error reporting. For example in error objects the file name is accessible through the "fileName" property if it's provided with this function.</p> <p><b>See also</b> <a class="obsolete" href="qscriptengine-obsolete.html#canEvaluate">canEvaluate</a>(), <a href="qscriptengine.html#hasUncaughtException">hasUncaughtException</a>(), <a href="qscriptengine.html#isEvaluating">isEvaluating</a>(), and <a href="qscriptengine.html#abortEvaluation">abortEvaluation</a>().</p> <h3 class="fn"><a name="globalObject" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.globalObject (<i>self</i>)</h3><p>Returns this engine's Global Object.</p> <p>By default, the Global Object contains the built-in objects that are part of <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm"> ECMA-262</a>, such as Math, Date and String. Additionally, you can set properties of the Global Object to make your own extensions available to all script code. Non-local variables in script code will be created as properties of the Global Object, as well as local variables in global code.</p> <p><b>See also</b> <a href="qscriptengine.html#setGlobalObject">setGlobalObject</a>().</p> <h3 class="fn"><a name="hasUncaughtException" />bool QScriptEngine.hasUncaughtException (<i>self</i>)</h3><p>Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false.</p> <p>The exception state is cleared when <a href="qscriptengine.html#evaluate">evaluate</a>() is called.</p> <p><b>See also</b> <a href="qscriptengine.html#uncaughtException">uncaughtException</a>() and <a href="qscriptengine.html#uncaughtExceptionLineNumber">uncaughtExceptionLineNumber</a>().</p> <h3 class="fn"><a name="importedExtensions" />QStringList QScriptEngine.importedExtensions (<i>self</i>)</h3><p>Returns a list naming the extensions that have been imported using the <a href="qscriptengine.html#importExtension">importExtension</a>() function.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#availableExtensions">availableExtensions</a>().</p> <h3 class="fn"><a name="importExtension" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.importExtension (<i>self</i>, QString <i>extension</i>)</h3><p>Imports the given <i>extension</i> into this <a href="qscriptengine.html">QScriptEngine</a>. Returns <a href="qscriptengine.html#undefinedValue">undefinedValue</a>() if the extension was successfully imported. You can call <a href="qscriptengine.html#hasUncaughtException">hasUncaughtException</a>() to check if an error occurred; in that case, the return value is the value that was thrown by the exception (usually an <tt>Error</tt> object).</p> <p><a href="qscriptengine.html">QScriptEngine</a> ensures that a particular extension is only imported once; subsequent calls to importExtension() with the same extension name will do nothing and return <a href="qscriptengine.html#undefinedValue">undefinedValue</a>().</p> <p><b>See also</b> <a href="qscriptengine.html#availableExtensions">availableExtensions</a>(), <a href="qscriptextensionplugin.html">QScriptExtensionPlugin</a>, and <a href="qtscriptextensions.html">Creating QtScript Extensions</a>.</p> <h3 class="fn"><a name="installTranslatorFunctions" />QScriptEngine.installTranslatorFunctions (<i>self</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>object</i> = QScriptValue())</h3><p>Installs translator functions on the given <i>object</i>, or on the Global Object if no object is specified.</p> <p>The relation between Qt Script translator functions and C++ translator functions is described in the following table:</p> <table class="generic"> <thead> <tr class="qt-style"> <th>Script Function</th> <th>Corresponding C++ Function</th> </tr> </thead> <tr class="odd" valign="top"> <td>qsTr()</td> <td><a href="qobject.html#tr">QObject.tr</a>()</td> </tr> <tr class="even" valign="top"> <td><a href="qtcore.html#QT_TR_NOOP">QT_TR_NOOP</a>()</td> <td><a href="qtcore.html#QT_TR_NOOP">QT_TR_NOOP</a>()</td> </tr> <tr class="odd" valign="top"> <td>qsTranslate()</td> <td><a href="qcoreapplication.html#translate">QCoreApplication.translate</a>()</td> </tr> <tr class="even" valign="top"> <td><a href="qtcore.html#QT_TRANSLATE_NOOP">QT_TRANSLATE_NOOP</a>()</td> <td><a href="qtcore.html#QT_TRANSLATE_NOOP">QT_TRANSLATE_NOOP</a>()</td> </tr> <tr class="odd" valign="top"> <td>qsTrId() (since 4.7)</td> <td><a href="qtcore.html#qtTrId">qtTrId</a>()</td> </tr> <tr class="even" valign="top"> <td><a href="qtcore.html#QT_TRID_NOOP">QT_TRID_NOOP</a>() (since 4.7)</td> <td><a href="qtcore.html#QT_TRID_NOOP">QT_TRID_NOOP</a>()</td> </tr> </table> <p>This function was introduced in Qt 4.5.</p> <p><b>See also</b> <a href="internationalization.html">Internationalization with Qt</a>.</p> <h3 class="fn"><a name="isEvaluating" />bool QScriptEngine.isEvaluating (<i>self</i>)</h3><p>Returns true if this engine is currently evaluating a script, otherwise returns false.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#evaluate">evaluate</a>() and <a href="qscriptengine.html#abortEvaluation">abortEvaluation</a>().</p> <h3 class="fn"><a name="newArray" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newArray (<i>self</i>, int <i>length</i> = 0)</h3><p>Creates a <a href="qtscript.html">QtScript</a> object of class Array with the given <i>length</i>.</p> <p><b>See also</b> <a href="qscriptengine.html#newObject">newObject</a>().</p> <h3 class="fn"><a name="newDate" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newDate (<i>self</i>, float <i>value</i>)</h3><p>Creates a <a href="qtscript.html">QtScript</a> object of class Date with the given <i>value</i> (the number of milliseconds since 01 January 1970, UTC).</p> <h3 class="fn"><a name="newDate-2" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newDate (<i>self</i>, <a href="qdatetime.html">QDateTime</a> <i>value</i>)</h3><p>Creates a <a href="qtscript.html">QtScript</a> object of class Date from the given <i>value</i>.</p> <p><b>See also</b> <a href="qscriptvalue.html#toDateTime">QScriptValue.toDateTime</a>().</p> <h3 class="fn"><a name="newFunction" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newFunction (<i>self</i>, callable <i>signature</i>, int <i>length</i> = 0)</h3><p>Creates a <a href="qscriptvalue.html">QScriptValue</a> that wraps a native (C++) function. <i>fun</i> must be a C++ function with signature <a href="qscriptengine.html#FunctionSignature-typedef">QScriptEngine.FunctionSignature</a>. <i>length</i> is the number of arguments that <i>fun</i> expects; this becomes the <tt>length</tt> property of the created <a href="qscriptvalue.html">QScriptValue</a>.</p> <p>Note that <i>length</i> only gives an indication of the number of arguments that the function expects; an actual invocation of a function can include any number of arguments. You can check the <a href="qscriptcontext.html#argumentCount">argumentCount()</a> of the <a href="qscriptcontext.html">QScriptContext</a> associated with the invocation to determine the actual number of arguments passed.</p> <p>A <tt>prototype</tt> property is automatically created for the resulting function object, to provide for the possibility that the function will be used as a constructor.</p> <p>By combining newFunction() and the property flags <a href="qscriptvalue.html#PropertyFlag-enum">QScriptValue.PropertyGetter</a> and <a href="qscriptvalue.html#PropertyFlag-enum">QScriptValue.PropertySetter</a>, you can create script object properties that behave like normal properties in script code, but are in fact accessed through functions (analogous to how properties work in <a href="properties.html#qt-s-property-system">Qt's Property System</a>). Example:</p> <pre class="cpp"> <span class="keyword">static</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> getSetFoo(<span class="type"><a href="qscriptcontext.html">QScriptContext</a></span> <span class="operator">*</span>context<span class="operator">,</span> <span class="type"><a href="qscriptengine.html">QScriptEngine</a></span> <span class="operator">*</span>engine) { <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> callee <span class="operator">=</span> context<span class="operator">-</span><span class="operator">></span>callee(); <span class="keyword">if</span> (context<span class="operator">-</span><span class="operator">></span>argumentCount() <span class="operator">=</span><span class="operator">=</span> <span class="number">1</span>) <span class="comment">// writing?</span> callee<span class="operator">.</span>setProperty(<span class="string">"value"</span><span class="operator">,</span> context<span class="operator">-</span><span class="operator">></span>argument(<span class="number">0</span>)); <span class="keyword">return</span> callee<span class="operator">.</span>property(<span class="string">"value"</span>); } <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> object <span class="operator">=</span> engine<span class="operator">.</span><a href="qscriptengine.html#newObject">newObject</a>(); object<span class="operator">.</span><a href="qobject.html#setProperty">setProperty</a>(<span class="string">"foo"</span><span class="operator">,</span> engine<span class="operator">.</span>newFunction(getSetFoo)<span class="operator">,</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span><span class="operator">.</span>PropertyGetter <span class="operator">|</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span><span class="operator">.</span>PropertySetter); </pre> <p>When the property <tt>foo</tt> of the script object is subsequently accessed in script code, <tt>getSetFoo()</tt> will be invoked to handle the access. In this particular case, we chose to store the "real" value of <tt>foo</tt> as a property of the accessor function itself; you are of course free to do whatever you like in this function.</p> <p>In the above example, a single native function was used to handle both reads and writes to the property; the argument count is used to determine if we are handling a read or write. You can also use two separate functions; just specify the relevant flag (<a href="qscriptvalue.html#PropertyFlag-enum">QScriptValue.PropertyGetter</a> or <a href="qscriptvalue.html#PropertyFlag-enum">QScriptValue.PropertySetter</a>) when setting the property, e.g.:</p> <pre class="cpp"> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> object <span class="operator">=</span> engine<span class="operator">.</span><a href="qscriptengine.html#newObject">newObject</a>(); object<span class="operator">.</span><a href="qobject.html#setProperty">setProperty</a>(<span class="string">"foo"</span><span class="operator">,</span> engine<span class="operator">.</span>newFunction(getFoo)<span class="operator">,</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span><span class="operator">.</span>PropertyGetter); object<span class="operator">.</span><a href="qobject.html#setProperty">setProperty</a>(<span class="string">"foo"</span><span class="operator">,</span> engine<span class="operator">.</span>newFunction(setFoo)<span class="operator">,</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span><span class="operator">.</span>PropertySetter); </pre> <p><b>See also</b> <a href="qscriptvalue.html#call">QScriptValue.call</a>().</p> <h3 class="fn"><a name="newFunction-2" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newFunction (<i>self</i>, callable <i>signature</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>prototype</i>, int <i>length</i> = 0)</h3><p>Creates a constructor function from <i>fun</i>, with the given <i>length</i>. The <tt>prototype</tt> property of the resulting function is set to be the given <i>prototype</i>. The <tt>constructor</tt> property of <i>prototype</i> is set to be the resulting function.</p> <p>When a function is called as a constructor (e.g. <tt>new Foo()</tt>), the `this' object associated with the function call is the new object that the function is expected to initialize; the prototype of this default constructed object will be the function's public <tt>prototype</tt> property. If you always want the function to behave as a constructor (e.g. <tt>Foo()</tt> should also create a new object), or if you need to create your own object rather than using the default `this' object, you should make sure that the prototype of your object is set correctly; either by setting it manually, or, when wrapping a custom type, by having registered the <a href="qscriptengine.html#defaultPrototype">defaultPrototype</a>() of that type. Example:</p> <pre class="cpp"> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> Foo(<span class="type"><a href="qscriptcontext.html">QScriptContext</a></span> <span class="operator">*</span>context<span class="operator">,</span> <span class="type"><a href="qscriptengine.html">QScriptEngine</a></span> <span class="operator">*</span>engine) { <span class="keyword">if</span> (context<span class="operator">-</span><span class="operator">></span>calledAsConstructor()) { <span class="comment">// initialize the new object</span> context<span class="operator">-</span><span class="operator">></span>thisObject()<span class="operator">.</span>setProperty(<span class="string">"bar"</span><span class="operator">,</span> <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>); <span class="comment">// ...</span> <span class="comment">// return a non-object value to indicate that the</span> <span class="comment">// thisObject() should be the result of the "new Foo()" expression</span> <span class="keyword">return</span> engine<span class="operator">-</span><span class="operator">></span>undefinedValue(); } <span class="keyword">else</span> { <span class="comment">// not called as "new Foo()", just "Foo()"</span> <span class="comment">// create our own object and return that one</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> object <span class="operator">=</span> engine<span class="operator">-</span><span class="operator">></span>newObject(); object<span class="operator">.</span>setPrototype(context<span class="operator">-</span><span class="operator">></span>callee()<span class="operator">.</span>property(<span class="string">"prototype"</span>)); object<span class="operator">.</span>setProperty(<span class="string">"baz"</span><span class="operator">,</span> <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>); <span class="keyword">return</span> object; } } <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> fooProto <span class="operator">=</span> engine<span class="operator">-</span><span class="operator">></span><a href="qscriptengine.html#newObject">newObject</a>(); fooProto<span class="operator">.</span><a href="qobject.html#setProperty">setProperty</a>(<span class="string">"whatever"</span><span class="operator">,</span> <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>); engine<span class="operator">-</span><span class="operator">></span><a href="qscriptengine.html#globalObject">globalObject</a>()<span class="operator">.</span><a href="qobject.html#setProperty">setProperty</a>(<span class="string">"Foo"</span><span class="operator">,</span> engine<span class="operator">-</span><span class="operator">></span>newFunction(Foo<span class="operator">,</span> fooProto)); </pre> <p>To wrap a custom type and provide a constructor for it, you'd typically do something like this:</p> <pre class="cpp"> <span class="keyword">class</span> Bar { <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> }; <a href="qmetatype.html#Q_DECLARE_METATYPE">Q_DECLARE_METATYPE</a>(Bar) <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> constructBar(<span class="type"><a href="qscriptcontext.html">QScriptContext</a></span> <span class="operator">*</span>context<span class="operator">,</span> <span class="type"><a href="qscriptengine.html">QScriptEngine</a></span> <span class="operator">*</span>engine) { Bar bar; <span class="comment">// initialize from arguments in context, if desired</span> <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="keyword">return</span> engine<span class="operator">-</span><span class="operator">></span>toScriptValue(bar); } <span class="keyword">class</span> BarPrototype : <span class="keyword">public</span> <span class="type"><a href="qobject.html">QObject</a></span><span class="operator">,</span> <span class="keyword">public</span> <span class="type"><a href="qscriptable.html">QScriptable</a></span> { <span class="comment">// provide the scriptable interface of this type using slots and properties</span> <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> }; <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="comment">// create and register the Bar prototype and constructor in the engine</span> BarPrototype <span class="operator">*</span>barPrototypeObject <span class="operator">=</span> <span class="keyword">new</span> BarPrototype(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>); <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> barProto <span class="operator">=</span> engine<span class="operator">-</span><span class="operator">></span><a href="qscriptengine.html#newQObject">newQObject</a>(barPrototypeObject); engine<span class="operator">-</span><span class="operator">></span><a href="qscriptengine.html#setDefaultPrototype">setDefaultPrototype</a>(<a href="qmetatype.html#qMetaTypeId">qMetaTypeId</a><span class="operator"><</span>Bar<span class="operator">></span><span class="operator">,</span> barProto); <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> barCtor <span class="operator">=</span> engine<span class="operator">-</span><span class="operator">></span><a href="qscriptengine.html#newFunction">newFunction</a>(constructBar<span class="operator">,</span> barProto); engine<span class="operator">-</span><span class="operator">></span><a href="qscriptengine.html#globalObject">globalObject</a>()<span class="operator">.</span><a href="qobject.html#setProperty">setProperty</a>(<span class="string">"Bar"</span><span class="operator">,</span> barCtor); </pre> <h3 class="fn"><a name="newObject" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newObject (<i>self</i>)</h3><p>Creates a <a href="qtscript.html">QtScript</a> object of class Object.</p> <p>The prototype of the created object will be the Object prototype object.</p> <p><b>See also</b> <a href="qscriptengine.html#newArray">newArray</a>() and <a href="qscriptvalue.html#setProperty">QScriptValue.setProperty</a>().</p> <h3 class="fn"><a name="newObject-2" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newObject (<i>self</i>, <a href="qscriptclass.html">QScriptClass</a> <i>scriptClass</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>data</i> = QScriptValue())</h3><p>This is an overloaded function.</p> <p>Creates a <a href="qtscript.html">QtScript</a> Object of the given class, <i>scriptClass</i>.</p> <p>The prototype of the created object will be the Object prototype object.</p> <p><i>data</i>, if specified, is set as the internal data of the new object (using <a href="qscriptvalue.html#setData">QScriptValue.setData</a>()).</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptvalue.html#scriptClass">QScriptValue.scriptClass</a>() and <a href="qscriptengine.html#reportAdditionalMemoryCost">reportAdditionalMemoryCost</a>().</p> <h3 class="fn"><a name="newQMetaObject" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newQMetaObject (<i>self</i>, <a href="qmetaobject.html">QMetaObject</a> <i>metaObject</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>ctor</i> = QScriptValue())</h3><p>Creates a <a href="qtscript.html">QtScript</a> object that represents a <a href="qobject.html">QObject</a> class, using the the given <i>metaObject</i> and constructor <i>ctor</i>.</p> <p>Enums of <i>metaObject</i> (declared with Q_ENUMS) are available as properties of the created <a href="qscriptvalue.html">QScriptValue</a>. When the class is called as a function, <i>ctor</i> will be called to create a new instance of the class.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> mySpecialQObjectConstructor(<span class="type"><a href="qscriptcontext.html">QScriptContext</a></span> <span class="operator">*</span>context<span class="operator">,</span> <span class="type"><a href="qscriptengine.html">QScriptEngine</a></span> <span class="operator">*</span>engine) { <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent <span class="operator">=</span> context<span class="operator">-</span><span class="operator">></span>argument(<span class="number">0</span>)<span class="operator">.</span>toQObject(); <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>object <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qobject.html">QObject</a></span>(parent); <span class="keyword">return</span> engine<span class="operator">-</span><span class="operator">></span>newQObject(object<span class="operator">,</span> <span class="type"><a href="qscriptengine.html">QScriptEngine</a></span><span class="operator">.</span>ScriptOwnership); } <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> ctor <span class="operator">=</span> engine<span class="operator">.</span>newFunction(mySpecialQObjectConstructor); <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> metaObject <span class="operator">=</span> engine<span class="operator">.</span>newQMetaObject(<span class="operator">&</span><span class="type"><a href="qobject.html">QObject</a></span><span class="operator">.</span>staticMetaObject<span class="operator">,</span> ctor); engine<span class="operator">.</span>globalObject()<span class="operator">.</span>setProperty(<span class="string">"QObject"</span><span class="operator">,</span> metaObject); <span class="type"><a href="qscriptvalue.html">QScriptValue</a></span> result <span class="operator">=</span> engine<span class="operator">.</span>evaluate(<span class="string">"new QObject()"</span>); </pre> <p><b>See also</b> <a href="qscriptengine.html#newQObject">newQObject</a>() and <a href="qscriptengine.html#scriptValueFromQMetaObject">scriptValueFromQMetaObject</a>().</p> <h3 class="fn"><a name="newQObject" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newQObject (<i>self</i>, <a href="qobject.html">QObject</a> <i>object</i>, <a href="qscriptengine.html#ValueOwnership-enum">ValueOwnership</a> <i>ownership</i> = QScriptEngine.QtOwnership, <a href="qscriptengine-qobjectwrapoptions.html">QObjectWrapOptions</a> <i>options</i> = 0)</h3><p>Creates a <a href="qtscript.html">QtScript</a> object that wraps the given <a href="qobject.html">QObject</a> <i>object</i>, using the given <i>ownership</i>. The given <i>options</i> control various aspects of the interaction with the resulting script object.</p> <p>Signals and slots, properties and children of <i>object</i> are available as properties of the created <a href="qscriptvalue.html">QScriptValue</a>. For more information, see the <a href="qtscript.html">QtScript</a> documentation.</p> <p>If <i>object</i> is a null pointer, this function returns <a href="qscriptengine.html#nullValue">nullValue</a>().</p> <p>If a default prototype has been registered for the <i>object</i>'s class (or its superclass, recursively), the prototype of the new script object will be set to be that default prototype.</p> <p>If the given <i>object</i> is deleted outside of <a href="qtscript.html">QtScript</a>'s control, any attempt to access the deleted <a href="qobject.html">QObject</a>'s members through the <a href="qtscript.html">QtScript</a> wrapper object (either by script code or C++) will result in a script exception.</p> <p><b>See also</b> <a href="qscriptvalue.html#toQObject">QScriptValue.toQObject</a>() and <a href="qscriptengine.html#reportAdditionalMemoryCost">reportAdditionalMemoryCost</a>().</p> <h3 class="fn"><a name="newQObject-2" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newQObject (<i>self</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>scriptObject</i>, <a href="qobject.html">QObject</a> <i>qtObject</i>, <a href="qscriptengine.html#ValueOwnership-enum">ValueOwnership</a> <i>ownership</i> = QScriptEngine.QtOwnership, <a href="qscriptengine-qobjectwrapoptions.html">QObjectWrapOptions</a> <i>options</i> = 0)</h3><p>This is an overloaded function.</p> <p>Initializes the given <i>scriptObject</i> to hold the given <i>qtObject</i>, and returns the <i>scriptObject</i>.</p> <p>This function enables you to "promote" a plain Qt Script object (created by the <a href="qscriptengine.html#newObject">newObject</a>() function) to a <a href="qobject.html">QObject</a> proxy, or to replace the <a href="qobject.html">QObject</a> contained inside an object previously created by the <a href="qscriptengine.html#newQObject">newQObject</a>() function.</p> <p>The prototype() of the <i>scriptObject</i> will remain unchanged.</p> <p>If <i>scriptObject</i> is not an object, this function behaves like the normal <a href="qscriptengine.html#newQObject">newQObject</a>(), i.e. it creates a new script object and returns it.</p> <p>This function is useful when you want to provide a script constructor for a <a href="qobject.html">QObject</a>-based class. If your constructor is invoked in a <tt>new</tt> expression (<a href="qscriptcontext.html#isCalledAsConstructor">QScriptContext.isCalledAsConstructor</a>() returns true), you can pass <a href="qscriptcontext.html#thisObject">QScriptContext.thisObject</a>() (the default constructed script object) to this function to initialize the new object.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#reportAdditionalMemoryCost">reportAdditionalMemoryCost</a>().</p> <h3 class="fn"><a name="newRegExp" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newRegExp (<i>self</i>, <a href="qregexp.html">QRegExp</a> <i>regexp</i>)</h3><p>Creates a <a href="qtscript.html">QtScript</a> object of class RegExp with the given <i>regexp</i>.</p> <p><b>See also</b> <a href="qscriptvalue.html#toRegExp">QScriptValue.toRegExp</a>().</p> <h3 class="fn"><a name="newRegExp-2" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newRegExp (<i>self</i>, QString <i>pattern</i>, QString <i>flags</i>)</h3><p>Creates a <a href="qtscript.html">QtScript</a> object of class RegExp with the given <i>pattern</i> and <i>flags</i>.</p> <p>The legal flags are 'g' (global), 'i' (ignore case), and 'm' (multiline).</p> <h3 class="fn"><a name="newVariant" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newVariant (<i>self</i>, QVariant <i>value</i>)</h3><p>Creates a <a href="qtscript.html">QtScript</a> object holding the given variant <i>value</i>.</p> <p>If a default prototype has been registered with the meta type id of <i>value</i>, then the prototype of the created object will be that prototype; otherwise, the prototype will be the Object prototype object.</p> <p><b>See also</b> <a href="qscriptengine.html#setDefaultPrototype">setDefaultPrototype</a>(), <a href="qscriptvalue.html#toVariant">QScriptValue.toVariant</a>(), and <a href="qscriptengine.html#reportAdditionalMemoryCost">reportAdditionalMemoryCost</a>().</p> <h3 class="fn"><a name="newVariant-2" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.newVariant (<i>self</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>object</i>, QVariant <i>value</i>)</h3><p>This is an overloaded function.</p> <p>Initializes the given Qt Script <i>object</i> to hold the given variant <i>value</i>, and returns the <i>object</i>.</p> <p>This function enables you to "promote" a plain Qt Script object (created by the <a href="qscriptengine.html#newObject">newObject</a>() function) to a variant, or to replace the variant contained inside an object previously created by the <a href="qscriptengine.html#newVariant">newVariant</a>() function.</p> <p>The prototype() of the <i>object</i> will remain unchanged.</p> <p>If <i>object</i> is not an object, this function behaves like the normal <a href="qscriptengine.html#newVariant">newVariant</a>(), i.e. it creates a new script object and returns it.</p> <p>This function is useful when you want to provide a script constructor for a C++ type. If your constructor is invoked in a <tt>new</tt> expression (<a href="qscriptcontext.html#isCalledAsConstructor">QScriptContext.isCalledAsConstructor</a>() returns true), you can pass <a href="qscriptcontext.html#thisObject">QScriptContext.thisObject</a>() (the default constructed script object) to this function to initialize the new object.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#reportAdditionalMemoryCost">reportAdditionalMemoryCost</a>().</p> <h3 class="fn"><a name="nullValue" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.nullValue (<i>self</i>)</h3><p>Returns a <a href="qscriptvalue.html">QScriptValue</a> of the primitive type Null.</p> <p><b>See also</b> <a href="qscriptengine.html#undefinedValue">undefinedValue</a>().</p> <h3 class="fn"><a name="popContext" />QScriptEngine.popContext (<i>self</i>)</h3><p>Pops the current execution context and restores the previous one. This function must be used in conjunction with <a href="qscriptengine.html#pushContext">pushContext</a>().</p> <p><b>See also</b> <a href="qscriptengine.html#pushContext">pushContext</a>().</p> <h3 class="fn"><a name="processEventsInterval" />int QScriptEngine.processEventsInterval (<i>self</i>)</h3><p>Returns the interval in milliseconds between calls to <a href="qcoreapplication.html#processEvents">QCoreApplication.processEvents</a>() while the interpreter is running.</p> <p><b>See also</b> <a href="qscriptengine.html#setProcessEventsInterval">setProcessEventsInterval</a>().</p> <h3 class="fn"><a name="pushContext" /><a href="qscriptcontext.html">QScriptContext</a> QScriptEngine.pushContext (<i>self</i>)</h3><p>Enters a new execution context and returns the associated <a href="qscriptcontext.html">QScriptContext</a> object.</p> <p>Once you are done with the context, you should call <a href="qscriptengine.html#popContext">popContext</a>() to restore the old context.</p> <p>By default, the `this' object of the new context is the Global Object. The context's <a href="qscriptcontext.html#callee">callee</a>() will be invalid.</p> <p>This function is useful when you want to evaluate script code as if it were the body of a function. You can use the context's <a href="qscriptcontext.html#activationObject">activationObject</a>() to initialize local variables that will be available to scripts. Example:</p> <pre class="cpp"> <span class="type"><a href="qscriptengine.html">QScriptEngine</a></span> engine; <span class="type"><a href="qscriptcontext.html">QScriptContext</a></span> <span class="operator">*</span>context <span class="operator">=</span> engine<span class="operator">.</span>pushContext(); context<span class="operator">-</span><span class="operator">></span>activationObject()<span class="operator">.</span>setProperty(<span class="string">"myArg"</span><span class="operator">,</span> <span class="number">123</span>); engine<span class="operator">.</span>evaluate(<span class="string">"var tmp = myArg + 42"</span>); <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> engine<span class="operator">.</span>popContext(); </pre> <p>In the above example, the new variable "tmp" defined in the script will be local to the context; in other words, the script doesn't have any effect on the global environment.</p> <p>Returns 0 in case of stack overflow</p> <p><b>See also</b> <a href="qscriptengine.html#popContext">popContext</a>().</p> <h3 class="fn"><a name="reportAdditionalMemoryCost" />QScriptEngine.reportAdditionalMemoryCost (<i>self</i>, int <i>size</i>)</h3><p>Reports an additional memory cost of the given <i>size</i>, measured in bytes, to the garbage collector.</p> <p>This function can be called to indicate that a Qt Script object has memory associated with it that isn't managed by Qt Script itself. Reporting the additional cost makes it more likely that the garbage collector will be triggered.</p> <p>Note that if the additional memory is shared with objects outside the scripting environment, the cost should not be reported, since collecting the Qt Script object would not cause the memory to be freed anyway.</p> <p>Negative <i>size</i> values are ignored, i.e. this function can't be used to report that the additional memory has been deallocated.</p> <p>This function was introduced in Qt 4.7.</p> <p><b>See also</b> <a href="qscriptengine.html#collectGarbage">collectGarbage</a>().</p> <h3 class="fn"><a name="setAgent" />QScriptEngine.setAgent (<i>self</i>, <a href="qscriptengineagent.html">QScriptEngineAgent</a> <i>agent</i>)</h3><p>Installs the given <i>agent</i> on this engine. The agent will be notified of various events pertaining to script execution. This is useful when you want to find out exactly what the engine is doing, e.g. when <a href="qscriptengine.html#evaluate">evaluate</a>() is called. The agent interface is the basis of tools like debuggers and profilers.</p> <p>The engine maintains ownership of the <i>agent</i>.</p> <p>Calling this function will replace the existing agent, if any.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#agent">agent</a>().</p> <h3 class="fn"><a name="setDefaultPrototype" />QScriptEngine.setDefaultPrototype (<i>self</i>, int <i>metaTypeId</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>prototype</i>)</h3><p>Sets the default prototype of the C++ type identified by the given <i>metaTypeId</i> to <i>prototype</i>.</p> <p>The default prototype provides a script interface for values of type <i>metaTypeId</i> when a value of that type is accessed from script code. Whenever the script engine (implicitly or explicitly) creates a <a href="qscriptvalue.html">QScriptValue</a> from a value of type <i>metaTypeId</i>, the default prototype will be set as the <a href="qscriptvalue.html">QScriptValue</a>'s prototype.</p> <p>The <i>prototype</i> object itself may be constructed using one of two principal techniques; the simplest is to subclass <a href="qscriptable.html">QScriptable</a>, which enables you to define the scripting API of the type through <a href="qobject.html">QObject</a> properties and slots. Another possibility is to create a script object by calling <a href="qscriptengine.html#newObject">newObject</a>(), and populate the object with the desired properties (e.g. native functions wrapped with <a href="qscriptengine.html#newFunction">newFunction</a>()).</p> <p><b>See also</b> <a href="qscriptengine.html#defaultPrototype">defaultPrototype</a>(), <a href="qscriptengine.html#qScriptRegisterMetaType">qScriptRegisterMetaType</a>(), <a href="qscriptable.html">QScriptable</a>, and <a href="script-defaultprototypes.html">Default Prototypes Example</a>.</p> <h3 class="fn"><a name="setGlobalObject" />QScriptEngine.setGlobalObject (<i>self</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>object</i>)</h3><p>Sets this engine's Global Object to be the given <i>object</i>. If <i>object</i> is not a valid script object, this function does nothing.</p> <p>When setting a custom global object, you may want to use <a href="qscriptvalueiterator.html">QScriptValueIterator</a> to copy the properties of the standard Global Object; alternatively, you can set the internal prototype of your custom object to be the original Global Object.</p> <p>This function was introduced in Qt 4.5.</p> <p><b>See also</b> <a href="qscriptengine.html#globalObject">globalObject</a>().</p> <h3 class="fn"><a name="setProcessEventsInterval" />QScriptEngine.setProcessEventsInterval (<i>self</i>, int <i>interval</i>)</h3><p>Sets the interval between calls to QCoreApplication.processEvents to <i>interval</i> milliseconds.</p> <p>While the interpreter is running, all event processing is by default blocked. This means for instance that the gui will not be updated and timers will not be fired. To allow event processing during interpreter execution one can specify the processing interval to be a positive value, indicating the number of milliseconds between each time <a href="qcoreapplication.html#processEvents">QCoreApplication.processEvents</a>() is called.</p> <p>The default value is -1, which disables event processing during interpreter execution.</p> <p>You can use <a href="qcoreapplication.html#postEvent">QCoreApplication.postEvent</a>() to post an event that performs custom processing at the next interval. For example, you could keep track of the total running time of the script and call <a href="qscriptengine.html#abortEvaluation">abortEvaluation</a>() when you detect that the script has been running for a long time without completing.</p> <p><b>See also</b> <a href="qscriptengine.html#processEventsInterval">processEventsInterval</a>().</p> <h3 class="fn"><a name="toObject" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.toObject (<i>self</i>, <a href="qscriptvalue.html">QScriptValue</a> <i>value</i>)</h3><p>Converts the given <i>value</i> to an object, if such a conversion is possible; otherwise returns an invalid <a href="qscriptvalue.html">QScriptValue</a>. The conversion is performed according to the following table:</p> <table class="generic"> <thead> <tr class="qt-style"> <th>Input Type</th> <th>Result</th> </tr> </thead> <tr class="odd" valign="top"> <td>Undefined</td> <td>An invalid <a href="qscriptvalue.html">QScriptValue</a>.</td> </tr> <tr class="even" valign="top"> <td>Null</td> <td>An invalid <a href="qscriptvalue.html">QScriptValue</a>.</td> </tr> <tr class="odd" valign="top"> <td>Boolean</td> <td>A new Boolean object whose internal value is set to the value of the boolean.</td> </tr> <tr class="even" valign="top"> <td>Number</td> <td>A new Number object whose internal value is set to the value of the number.</td> </tr> <tr class="odd" valign="top"> <td>String</td> <td>A new String object whose internal value is set to the value of the string.</td> </tr> <tr class="even" valign="top"> <td>Object</td> <td>The result is the object itself (no conversion).</td> </tr> </table> <p>This function was introduced in Qt 4.5.</p> <p><b>See also</b> <a href="qscriptengine.html#newObject">newObject</a>().</p> <h3 class="fn"><a name="toStringHandle" /><a href="qscriptstring.html">QScriptString</a> QScriptEngine.toStringHandle (<i>self</i>, QString <i>str</i>)</h3><p>Returns a handle that represents the given string, <i>str</i>.</p> <p><a href="qscriptstring.html">QScriptString</a> can be used to quickly look up properties, and compare property names, of script objects.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptvalue.html#property">QScriptValue.property</a>().</p> <h3 class="fn"><a name="uncaughtException" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.uncaughtException (<i>self</i>)</h3><p>Returns the current uncaught exception, or an invalid <a href="qscriptvalue.html">QScriptValue</a> if there is no uncaught exception.</p> <p>The exception value is typically an <tt>Error</tt> object; in that case, you can call toString() on the return value to obtain an error message.</p> <p><b>See also</b> <a href="qscriptengine.html#hasUncaughtException">hasUncaughtException</a>() and <a href="qscriptengine.html#uncaughtExceptionLineNumber">uncaughtExceptionLineNumber</a>().</p> <h3 class="fn"><a name="uncaughtExceptionBacktrace" />QStringList QScriptEngine.uncaughtExceptionBacktrace (<i>self</i>)</h3><p>Returns a human-readable backtrace of the last uncaught exception.</p> <p>It is in the form <tt><function-name>()@<file-name>:<line-number></tt>.</p> <p><b>See also</b> <a href="qscriptengine.html#uncaughtException">uncaughtException</a>().</p> <h3 class="fn"><a name="uncaughtExceptionLineNumber" />int QScriptEngine.uncaughtExceptionLineNumber (<i>self</i>)</h3><p>Returns the line number where the last uncaught exception occurred.</p> <p>Line numbers are 1-based, unless a different base was specified as the second argument to <a href="qscriptengine.html#evaluate">evaluate</a>().</p> <p><b>See also</b> <a href="qscriptengine.html#hasUncaughtException">hasUncaughtException</a>().</p> <h3 class="fn"><a name="undefinedValue" /><a href="qscriptvalue.html">QScriptValue</a> QScriptEngine.undefinedValue (<i>self</i>)</h3><p>Returns a <a href="qscriptvalue.html">QScriptValue</a> of the primitive type Undefined.</p> <p><b>See also</b> <a href="qscriptengine.html#nullValue">nullValue</a>().</p> <hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="signalHandlerException" />void signalHandlerException (const QScriptValue&)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted when a script function connected to a signal causes an <i>exception</i>.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also</b> <a href="qscriptengine.html#qScriptConnect">qScriptConnect</a>().</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>