This file is indexed.

/usr/share/qt5/doc/qtqml/qjsengine.html is in qtdeclarative5-doc-html 5.5.1-2ubuntu6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qjsengine.cpp -->
  <title>QJSEngine Class | Qt QML 5.5</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
<li>Qt 5.5</li>
<li><a href="qtqml-index.html">Qt QML</a></li>
<li><a href="qtqml-module.html">C++ Classes</a></li>
<li>QJSEngine</li>
<li id="buildversion">Qt 5.5.1 Reference Documentation</li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#related-non-members">Related Non-Members</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#evaluating-scripts">Evaluating Scripts</a></li>
<li class="level2"><a href="#engine-configuration">Engine Configuration</a></li>
<li class="level2"><a href="#script-exceptions">Script Exceptions</a></li>
<li class="level2"><a href="#script-object-creation">Script Object Creation</a></li>
<li class="level2"><a href="#qobject-integration">QObject Integration</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QJSEngine Class</h1>
<!-- $$$QJSEngine-brief -->
<p>The <a href="qjsengine.html">QJSEngine</a> class provides an environment for evaluating JavaScript code. <a href="#details">More...</a></p>
<!-- @@@QJSEngine -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include &lt;QJSEngine&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += qml</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 5.0</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherited By:</td><td class="memItemRight bottomAlign"> <p><a href="qqmlengine.html">QQmlEngine</a></p>
</td></tr></table></div><p><b>Note:</b> All functions in this class are reentrant.</p>
<ul>
<li><a href="qjsengine-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#QJSEngine">QJSEngine</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#QJSEngine-2">QJSEngine</a></b>(QObject *<i> parent</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#dtor.QJSEngine">~QJSEngine</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#collectGarbage">collectGarbage</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QJSValue </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#evaluate">evaluate</a></b>(const QString &amp;<i> program</i>, const QString &amp;<i> fileName</i> = QString(), int<i> lineNumber</i> = 1)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#fromScriptValue">fromScriptValue</a></b>(const QJSValue &amp;<i> value</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QJSValue </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#globalObject">globalObject</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#installTranslatorFunctions">installTranslatorFunctions</a></b>(const QJSValue &amp;<i> object</i> = QJSValue())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QJSValue </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#newArray">newArray</a></b>(uint<i> length</i> = 0)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QJSValue </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#newObject">newObject</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QJSValue </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#newQObject">newQObject</a></b>(QObject *<i> object</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QJSValue </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#toScriptValue">toScriptValue</a></b>(const T &amp;<i> value</i>)</td></tr>
</table></div>
<a name="related-non-members"></a>
<h2 id="related-non-members">Related Non-Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QJSEngine * </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#qjsEnginex">qjsEngine</a></b>(const QObject *<i> object</i>)</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QJSEngine-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qjsengine.html">QJSEngine</a> class provides an environment for evaluating JavaScript code.</p>
<a name="evaluating-scripts"></a>
<h3 >Evaluating Scripts</h3>
<p>Use <a href="qjsengine.html#evaluate">evaluate</a>() to evaluate script code.</p>
<pre class="cpp"><span class="type"><a href="qjsengine.html#QJSEngine">QJSEngine</a></span> myEngine;
<span class="type"><a href="qjsvalue.html">QJSValue</a></span> three <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qjsengine.html#evaluate">evaluate</a>(<span class="string">&quot;1 + 2&quot;</span>);</pre>
<p><a href="qjsengine.html#evaluate">evaluate</a>() returns a <a href="qjsvalue.html">QJSValue</a> that holds the result of the evaluation. The <a href="qjsvalue.html">QJSValue</a> class provides functions for converting the result to various C++ types (e.g&#x2e; <a href="qjsvalue.html#toString">QJSValue::toString</a>() and <a href="qjsvalue.html#toNumber">QJSValue::toNumber</a>()).</p>
<p>The following code snippet shows how a script function can be defined and then invoked from C++ using <a href="qjsvalue.html#call">QJSValue::call</a>():</p>
<pre class="cpp"><span class="type"><a href="qjsvalue.html">QJSValue</a></span> fun <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qjsengine.html#evaluate">evaluate</a>(<span class="string">&quot;(function(a, b) { return a + b; })&quot;</span>);
<span class="type">QJSValueList</span> args;
args <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="number">1</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="number">2</span>;
<span class="type"><a href="qjsvalue.html">QJSValue</a></span> threeAgain <span class="operator">=</span> fun<span class="operator">.</span>call(<span class="type"><a href="qjsvalue.html">QJSValue</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="qjsengine.html#evaluate">evaluate</a>():</p>
<pre class="cpp"><span class="type">QString</span> fileName <span class="operator">=</span> <span class="string">&quot;helloworld.qs&quot;</span>;
<span class="type">QFile</span> scriptFile(fileName);
<span class="keyword">if</span> (<span class="operator">!</span>scriptFile<span class="operator">.</span>open(<span class="type">QIODevice</span><span class="operator">::</span>ReadOnly))
    <span class="comment">// handle error</span>
<span class="type">QTextStream</span> stream(<span class="operator">&amp;</span>scriptFile);
<span class="type">QString</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="qjsengine.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="qjsengine.html#evaluate">evaluate</a>(). This does not affect evaluation in any way; the second argument is a general-purpose string that is stored in the <code>Error</code> object for debugging purposes.</p>
<a name="engine-configuration"></a>
<h3 >Engine Configuration</h3>
<p>The <a href="qjsengine.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&#x2e; they are global variables). Typically, before evaluating &quot;user&quot; 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="qjsengine.html#globalObject">globalObject</a>()<span class="operator">.</span>setProperty(<span class="string">&quot;myNumber&quot;</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="qjsvalue.html">QJSValue</a></span> myNumberPlusOne <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qjsengine.html#evaluate">evaluate</a>(<span class="string">&quot;myNumber + 1&quot;</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="qjsengine.html#newQObject">newQObject</a>() or <a href="qjsengine.html#newObject">newObject</a>() functions.</p>
<a name="script-exceptions"></a>
<h3 >Script Exceptions</h3>
<p><a href="qjsengine.html#evaluate">evaluate</a>() can throw a script exception (e.g&#x2e; due to a syntax error). If it does, then <a href="qjsengine.html#evaluate">evaluate</a>() returns the value that was thrown (typically an <code>Error</code> object). Use <a href="qjsvalue.html#isError">QJSValue::isError</a>() to check for exceptions.</p>
<p>For detailed information about the error, use <a href="qjsvalue.html#toString">QJSValue::toString</a>() to obtain an error message, and use <a href="qjsvalue.html#property">QJSValue::property</a>() to query the properties of the <code>Error</code> object. The following properties are available:</p>
<ul>
<li><code>name</code></li>
<li><code>message</code></li>
<li><code>fileName</code></li>
<li><code>lineNumber</code></li>
<li><code>stack</code></li>
</ul>
<pre class="cpp"><span class="type"><a href="qjsvalue.html">QJSValue</a></span> result <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qjsengine.html#evaluate">evaluate</a>(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>);
<span class="keyword">if</span> (result<span class="operator">.</span>isError())
    qDebug()
            <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Uncaught exception at line&quot;</span>
            <span class="operator">&lt;</span><span class="operator">&lt;</span> result<span class="operator">.</span>property(<span class="string">&quot;lineNumber&quot;</span>)<span class="operator">.</span>toInt()
            <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;:&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> result<span class="operator">.</span>toString();</pre>
<a name="script-object-creation"></a>
<h3 >Script Object Creation</h3>
<p>Use <a href="qjsengine.html#newObject">newObject</a>() to create a JavaScript object; this is the C++ equivalent of the script statement <code>new Object()</code>. You can use the object-specific functionality in <a href="qjsvalue.html">QJSValue</a> to manipulate the script object (e.g&#x2e; <a href="qjsvalue.html#setProperty">QJSValue::setProperty</a>()). Similarly, use <a href="qjsengine.html#newArray">newArray</a>() to create a JavaScript array object.</p>
<a name="qobject-integration"></a>
<h3 >QObject Integration</h3>
<p>Use <a href="qjsengine.html#newQObject">newQObject</a>() to wrap a QObject (or subclass) pointer. <a href="qjsengine.html#newQObject">newQObject</a>() returns a proxy script object; properties, children, and signals and slots of the QObject 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">QPushButton</span> <span class="operator">*</span>button <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QPushButton</span>;
<span class="type"><a href="qjsvalue.html">QJSValue</a></span> scriptButton <span class="operator">=</span> myEngine<span class="operator">.</span><a href="qjsengine.html#newQObject">newQObject</a>(button);
myEngine<span class="operator">.</span><a href="qjsengine.html#globalObject">globalObject</a>()<span class="operator">.</span>setProperty(<span class="string">&quot;button&quot;</span><span class="operator">,</span> scriptButton);

myEngine<span class="operator">.</span><a href="qjsengine.html#evaluate">evaluate</a>(<span class="string">&quot;button.checkable = true&quot;</span>);

qDebug() <span class="operator">&lt;</span><span class="operator">&lt;</span> scriptButton<span class="operator">.</span>property(<span class="string">&quot;checkable&quot;</span>)<span class="operator">.</span>toBool();
scriptButton<span class="operator">.</span>property(<span class="string">&quot;show&quot;</span>)<span class="operator">.</span>call(); <span class="comment">// call the show() slot</span></pre>
</div>
<p><b>See also </b><a href="qjsvalue.html">QJSValue</a> and <a href="qtjavascript.html">Making Applications Scriptable</a>.</p>
<!-- @@@QJSEngine -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QJSEngine[overload1]$$$QJSEngine -->
<h3 class="fn" id="QJSEngine"><a name="QJSEngine"></a>QJSEngine::<span class="name">QJSEngine</span>()</h3>
<p>Constructs a <a href="qjsengine.html">QJSEngine</a> object.</p>
<p>The <a href="qjsengine.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&#x2e;</p>
<!-- @@@QJSEngine -->
<!-- $$$QJSEngine$$$QJSEngineQObject* -->
<h3 class="fn" id="QJSEngine-2"><a name="QJSEngine-2"></a>QJSEngine::<span class="name">QJSEngine</span>(<span class="type">QObject</span> *<i> parent</i>)</h3>
<p>Constructs a <a href="qjsengine.html">QJSEngine</a> object with the given <i>parent</i>.</p>
<p>The <a href="qjsengine.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&#x2e;</p>
<!-- @@@QJSEngine -->
<!-- $$$~QJSEngine[overload1]$$$~QJSEngine -->
<h3 class="fn" id="dtor.QJSEngine"><a name="dtor.QJSEngine"></a><code>[virtual] </code>QJSEngine::<span class="name">~QJSEngine</span>()</h3>
<p>Destroys this <a href="qjsengine.html">QJSEngine</a>.</p>
<p>Garbage is not collected from the persistent JS heap during <a href="qjsengine.html">QJSEngine</a> destruction. If you need all memory freed, call <a href="qjsengine.html#collectGarbage">collectGarbage</a> manually right before destroying the <a href="qjsengine.html">QJSEngine</a>.</p>
<!-- @@@~QJSEngine -->
<!-- $$$collectGarbage[overload1]$$$collectGarbage -->
<h3 class="fn" id="collectGarbage"><a name="collectGarbage"></a><span class="type">void</span> QJSEngine::<span class="name">collectGarbage</span>()</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="qjsengine.html">QJSEngine</a> decides that it's wise to do so (i.e&#x2e; 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>
<!-- @@@collectGarbage -->
<!-- $$$evaluate[overload1]$$$evaluateconstQString&constQString&int -->
<h3 class="fn" id="evaluate"><a name="evaluate"></a><span class="type"><a href="qjsvalue.html">QJSValue</a></span> QJSEngine::<span class="name">evaluate</span>(const <span class="type">QString</span> &amp;<i> program</i>, const <span class="type">QString</span> &amp;<i> fileName</i> = QString(), <span class="type">int</span><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 context of the global object.</p>
<p>The evaluation of <i>program</i> can cause an <a href="qjsengine.html#script-exceptions">exception</a> in the engine; in this case the return value will be the exception that was thrown (typically an <code>Error</code> object; see <a href="qjsvalue.html#isError">QJSValue::isError</a>()).</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 pertains to this evaluation 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, the exception line number would be <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 &quot;fileName&quot; property if it is provided with this function.</p>
<p><b>Note: </b>If an exception was thrown and the exception value is not an Error instance (i.e&#x2e;, <a href="qjsvalue.html#isError">QJSValue::isError</a>() returns <code>false</code>), the exception value will still be returned, but there is currently no API for detecting that an exception did occur in this case.</p><!-- @@@evaluate -->
<!-- $$$fromScriptValue[overload1]$$$fromScriptValueconstQJSValue& -->
<h3 class="fn" id="fromScriptValue"><a name="fromScriptValue"></a><span class="type">T</span> QJSEngine::<span class="name">fromScriptValue</span>(const <span class="type"><a href="qjsvalue.html">QJSValue</a></span> &amp;<i> value</i>)</h3>
<p>Returns the given <i>value</i> converted to the template type <code>T</code>.</p>
<p><b>See also </b><a href="qjsengine.html#toScriptValue">toScriptValue</a>().</p>
<!-- @@@fromScriptValue -->
<!-- $$$globalObject[overload1]$$$globalObject -->
<h3 class="fn" id="globalObject"><a name="globalObject"></a><span class="type"><a href="qjsvalue.html">QJSValue</a></span> QJSEngine::<span class="name">globalObject</span>() const</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>
<!-- @@@globalObject -->
<!-- $$$installTranslatorFunctions[overload1]$$$installTranslatorFunctionsconstQJSValue& -->
<h3 class="fn" id="installTranslatorFunctions"><a name="installTranslatorFunctions"></a><span class="type">void</span> QJSEngine::<span class="name">installTranslatorFunctions</span>(const <span class="type"><a href="qjsvalue.html">QJSValue</a></span> &amp;<i> object</i> = QJSValue())</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 script translator functions and C++ translator functions is described in the following table:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Script Function</th><th >Corresponding C++ Function</th></tr></thead>
<tr valign="top" class="odd"><td >qsTr()</td><td >QObject::tr()</td></tr>
<tr valign="top" class="even"><td >QT_TR_NOOP()</td><td >QT_TR_NOOP()</td></tr>
<tr valign="top" class="odd"><td >qsTranslate()</td><td >QCoreApplication::translate()</td></tr>
<tr valign="top" class="even"><td >QT_TRANSLATE_NOOP()</td><td >QT_TRANSLATE_NOOP()</td></tr>
<tr valign="top" class="odd"><td >qsTrId()</td><td >qtTrId()</td></tr>
<tr valign="top" class="even"><td >QT_TRID_NOOP()</td><td >QT_TRID_NOOP()</td></tr>
</table></div>
<p>It also adds an arg() method to the string prototype.</p>
<p>This function was introduced in  Qt 5.4.</p>
<p><b>See also </b>Internationalization with Qt.</p>
<!-- @@@installTranslatorFunctions -->
<!-- $$$newArray[overload1]$$$newArrayuint -->
<h3 class="fn" id="newArray"><a name="newArray"></a><span class="type"><a href="qjsvalue.html">QJSValue</a></span> QJSEngine::<span class="name">newArray</span>(<span class="type">uint</span><i> length</i> = 0)</h3>
<p>Creates a JavaScript object of class Array with the given <i>length</i>.</p>
<p><b>See also </b><a href="qjsengine.html#newObject">newObject</a>().</p>
<!-- @@@newArray -->
<!-- $$$newObject[overload1]$$$newObject -->
<h3 class="fn" id="newObject"><a name="newObject"></a><span class="type"><a href="qjsvalue.html">QJSValue</a></span> QJSEngine::<span class="name">newObject</span>()</h3>
<p>Creates a JavaScript 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="qjsengine.html#newArray">newArray</a>() and <a href="qjsvalue.html#setProperty">QJSValue::setProperty</a>().</p>
<!-- @@@newObject -->
<!-- $$$newQObject[overload1]$$$newQObjectQObject* -->
<h3 class="fn" id="newQObject"><a name="newQObject"></a><span class="type"><a href="qjsvalue.html">QJSValue</a></span> QJSEngine::<span class="name">newQObject</span>(<span class="type">QObject</span> *<i> object</i>)</h3>
<p>Creates a JavaScript object that wraps the given QObject <i>object</i>, using JavaScriptOwnership.</p>
<p>Signals and slots, properties and children of <i>object</i> are available as properties of the created <a href="qjsvalue.html">QJSValue</a>.</p>
<p>If <i>object</i> is a null pointer, this function returns a null value.</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 the engine's control, any attempt to access the deleted QObject's members through the JavaScript wrapper object (either by script code or C++) will result in a <a href="qjsengine.html#script-exceptions">script exception</a>.</p>
<p><b>See also </b><a href="qjsvalue.html#toQObject">QJSValue::toQObject</a>().</p>
<!-- @@@newQObject -->
<!-- $$$toScriptValue[overload1]$$$toScriptValueconstT& -->
<h3 class="fn" id="toScriptValue"><a name="toScriptValue"></a><span class="type"><a href="qjsvalue.html">QJSValue</a></span> QJSEngine::<span class="name">toScriptValue</span>(const <span class="type">T</span> &amp;<i> value</i>)</h3>
<p>Creates a <a href="qjsvalue.html">QJSValue</a> with the given <i>value</i>.</p>
<p><b>See also </b><a href="qjsengine.html#fromScriptValue">fromScriptValue</a>() and newVariant().</p>
<!-- @@@toScriptValue -->
</div>
<div class="relnonmem">
<h2>Related Non-Members</h2>
<!-- $$$qjsEngine[overload1]$$$qjsEngineconstQObject* -->
<h3 class="fn" id="qjsEnginex"><a name="qjsEnginex"></a><span class="type"><a href="qjsengine.html#QJSEngine">QJSEngine</a></span> * <span class="name">qjsEngine</span>(const <span class="type">QObject</span> *<i> object</i>)</h3>
<p>Returns the <a href="qjsengine.html">QJSEngine</a> associated with <i>object</i>, if any.</p>
<p>This function is useful if you have exposed a QObject to the JavaScript environment and later in your program would like to regain access. It does not require you to keep the wrapper around that was returned from <a href="qjsengine.html#newQObject">QJSEngine::newQObject</a>().</p>
<p>This function was introduced in  Qt 5.5.</p>
<!-- @@@qjsEngine -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>