This file is indexed.

/usr/share/qt5/doc/qtqml/qjsengine.html is in qtdeclarative5-doc-html 5.9.5-0ubuntu1.

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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?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.9</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.9</td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-module.html">C++ Classes</a></td><td >QJSEngine</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.5 Reference Documentation</td>
        </tr></table>
      </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-types">Public Types</a></li>
<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>
<li class="level2"><a href="#extensions">Extensions</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"> <a href="../qtcore/qobject.html">QObject</a></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><ul>
<li><a href="qjsengine-members.html">List of all members, including inherited members</a></li>
<li><a href="qjsengine-obsolete.html">Obsolete members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are reentrant.</p>
<a name="public-types"></a>
<h2 id="public-types">Public Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#Extension-enum">Extension</a></b> { TranslationExtension, ConsoleExtension, GarbageCollectionExtension, AllExtensions }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> flags </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#Extension-enum">Extensions</a></b></td></tr>
</table></div>
<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-1">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#installExtensions">installExtensions</a></b>(Extensions <i>extensions</i>, 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#newQMetaObject">newQMetaObject</a></b>(const QMetaObject *<i>metaObject</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QJSValue </td><td class="memItemRight bottomAlign"><b><a href="qjsengine.html#newQMetaObject-1">newQMetaObject</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>
<ul>
<li class="fn">32 public functions inherited from <a href="../qtcore/qobject.html#public-functions">QObject</a></li>
</ul>
<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>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 property inherited from <a href="../qtcore/qobject.html#properties">QObject</a></li>
<li class="fn">1 public slot inherited from <a href="../qtcore/qobject.html#public-slots">QObject</a></li>
<li class="fn">2 signals inherited from <a href="../qtcore/qobject.html#signals">QObject</a></li>
<li class="fn">1 public variable inherited from <a href="../qtcore/qobject.html#public-variables">QObject</a></li>
<li class="fn">10 static public members inherited from <a href="../qtcore/qobject.html#static-public-members">QObject</a></li>
<li class="fn">9 protected functions inherited from <a href="../qtcore/qobject.html#protected-functions">QObject</a></li>
<li class="fn">2 protected variables inherited from <a href="../qtcore/qobject.html#protected-variables">QObject</a></li>
</ul>
<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>evaluate(<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>evaluate(<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"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> <span class="string">&quot;helloworld.qs&quot;</span>;
  <span class="type"><a href="../qtcore/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="../qtcore/qiodevice.html">QIODevice</a></span><span class="operator">::</span>ReadOnly))
      <span class="comment">// handle error</span>
  <span class="type"><a href="../qtcore/qtextstream.html">QTextStream</a></span> stream(<span class="operator">&amp;</span>scriptFile);
  <span class="type"><a href="../qtcore/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>evaluate(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>globalObject()<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>evaluate(<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>evaluate(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>);
  <span class="keyword">if</span> (result<span class="operator">.</span>isError())
      <a href="../qtcore/qtglobal.html#qDebug">qDebug</a>()
              <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 <a href="../qtcore/qobject.html">QObject</a> (or subclass) pointer. <a href="qjsengine.html#newQObject">newQObject</a>() returns a proxy script object; properties, children, and signals and slots of the <a href="../qtcore/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="../qtwidgets/qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>button <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtwidgets/qpushbutton.html">QPushButton</a></span>;
  <span class="type"><a href="qjsvalue.html">QJSValue</a></span> scriptButton <span class="operator">=</span> myEngine<span class="operator">.</span>newQObject(button);
  myEngine<span class="operator">.</span>globalObject()<span class="operator">.</span>setProperty(<span class="string">&quot;button&quot;</span><span class="operator">,</span> scriptButton);

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

  <a href="../qtcore/qtglobal.html#qDebug">qDebug</a>() <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>
<p>Use <a href="qjsengine.html#newQMetaObject-1">newQMetaObject</a>() to wrap a <a href="../qtcore/qmetaobject.html">QMetaObject</a>; this gives you a &quot;script representation&quot; of a <a href="../qtcore/qobject.html">QObject</a>-based class. <a href="qjsengine.html#newQMetaObject-1">newQMetaObject</a>() returns a proxy script object; enum values of the class are available as properties of the proxy object.</p>
<p>Constructors exposed to the meta-object system (using <a href="../qtcore/qobject.html#Q_INVOKABLE">Q_INVOKABLE</a>) can be called from the script to create a new <a href="../qtcore/qobject.html">QObject</a> instance with JavaScriptOwnership. For example, given the following class definition:</p>
<pre class="cpp">

  <span class="keyword">class</span> MyObject : <span class="keyword">public</span> <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span>
  {
      Q_OBJECT

  <span class="keyword">public</span>:
      Q_INVOKABLE MyObject() {}
  };

</pre>
<p>The <code>staticMetaObject</code> for the class can be exposed to JavaScript like so:</p>
<pre class="cpp">

  <span class="type"><a href="qjsvalue.html">QJSValue</a></span> jsMetaObject <span class="operator">=</span> engine<span class="operator">.</span>newQMetaObject(<span class="operator">&amp;</span>MyObject<span class="operator">::</span>staticMetaObject);
  engine<span class="operator">.</span>globalObject()<span class="operator">.</span>setProperty(<span class="string">&quot;MyObject&quot;</span><span class="operator">,</span> jsMetaObject);

</pre>
<p>Instances of the class can then be created in JavaScript:</p>
<pre class="cpp">

  engine<span class="operator">.</span>evaluate(<span class="string">&quot;var myObject = new MyObject()&quot;</span>);

</pre>
<p><b>Note: </b>Currently only classes using the <a href="../qtcore/qobject.html#Q_OBJECT">Q_OBJECT</a> macro are supported; it is not possible to expose the <code>staticMetaObject</code> of a <a href="../qtcore/qobject.html#Q_GADGET">Q_GADGET</a> class to JavaScript.</p><a name="dynamic-qobject-properties"></a>
<h4 >Dynamic QObject Properties</h4>
<p>Dynamic <a href="../qtcore/qobject.html">QObject</a> properties are not supported. For example, the following code will not work:</p>
<pre class="cpp">

  <span class="type"><a href="qjsengine.html#QJSEngine">QJSEngine</a></span> engine;

  <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> <span class="operator">*</span>myQObject <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span>();
  myQObject<span class="operator">-</span><span class="operator">&gt;</span>setProperty(<span class="string">&quot;dynamicProperty&quot;</span><span class="operator">,</span> <span class="number">3</span>);

  <span class="type"><a href="qjsvalue.html">QJSValue</a></span> myScriptQObject <span class="operator">=</span> engine<span class="operator">.</span>newQObject(myQObject);
  engine<span class="operator">.</span>globalObject()<span class="operator">.</span>setProperty(<span class="string">&quot;myObject&quot;</span><span class="operator">,</span> myScriptQObject);

  <a href="../qtcore/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> engine<span class="operator">.</span>evaluate(<span class="string">&quot;myObject.dynamicProperty&quot;</span>)<span class="operator">.</span>toInt();

</pre>
<a name="extensions"></a>
<h3 >Extensions</h3>
<p><a href="qjsengine.html">QJSEngine</a> provides a compliant ECMAScript implementation. By default, familiar utilities like logging are not available, but they can can be installed via the <a href="qjsengine.html#installExtensions">installExtensions</a>() function.</p>
</div>
<p><b>See also </b><a href="qjsvalue.html">QJSValue</a>, <a href="qtjavascript.html">Making Applications Scriptable</a>, and <a href="qtqml-javascript-functionlist.html">List of JavaScript Objects and Functions</a>.</p>
<!-- @@@QJSEngine -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$Extension$$$TranslationExtension$$$ConsoleExtension$$$GarbageCollectionExtension$$$AllExtensions -->
<h3 class="flags" id="Extension-enum"><a name="Extension-enum"></a>enum QJSEngine::<span class="name">Extension</span><br/>flags QJSEngine::<span class="name">Extensions</span></h3>
<p>This enum is used to specify extensions to be installed via <a href="qjsengine.html#installExtensions">installExtensions</a>().</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QJSEngine::TranslationExtension</code></td><td class="topAlign tblval"><code>0x1</code></td><td class="topAlign">Indicates that translation functions (<code>qsTr()</code>, for example) should be installed.</td></tr>
<tr><td class="topAlign"><code>QJSEngine::ConsoleExtension</code></td><td class="topAlign tblval"><code>0x2</code></td><td class="topAlign">Indicates that console functions (<code>console.log()</code>, for example) should be installed.</td></tr>
<tr><td class="topAlign"><code>QJSEngine::GarbageCollectionExtension</code></td><td class="topAlign tblval"><code>0x4</code></td><td class="topAlign">Indicates that garbage collection functions (<code>gc()</code>, for example) should be installed.</td></tr>
<tr><td class="topAlign"><code>QJSEngine::AllExtensions</code></td><td class="topAlign tblval"><code>0xffffffff</code></td><td class="topAlign">Indicates that all extension should be installed.</td></tr>
</table></div>
<p><b>TranslationExtension</b></p>
<p>The relation between script translation functions and C++ translation 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 ><a href="../qtcore/qobject.html#tr">QObject::tr</a>()</td></tr>
<tr valign="top" class="even"><td ><a href="../qtcore/qtglobal.html#QT_TR_NOOP">QT_TR_NOOP</a>()</td><td ><a href="../qtcore/qtglobal.html#QT_TR_NOOP">QT_TR_NOOP</a>()</td></tr>
<tr valign="top" class="odd"><td >qsTranslate()</td><td >QCoreApplication::translate()</td></tr>
<tr valign="top" class="even"><td ><a href="../qtcore/qtglobal.html#QT_TRANSLATE_NOOP">QT_TRANSLATE_NOOP</a>()</td><td ><a href="../qtcore/qtglobal.html#QT_TRANSLATE_NOOP">QT_TRANSLATE_NOOP</a>()</td></tr>
<tr valign="top" class="odd"><td >qsTrId()</td><td ><a href="../qtcore/qtglobal.html#qtTrId">qtTrId</a>()</td></tr>
<tr valign="top" class="even"><td ><a href="../qtcore/qtglobal.html#QT_TRID_NOOP">QT_TRID_NOOP</a>()</td><td ><a href="../qtcore/qtglobal.html#QT_TRID_NOOP">QT_TRID_NOOP</a>()</td></tr>
</table></div>
<p>This flag also adds an <code>arg()</code> function to the string prototype.</p>
<p>For more information, see the Internationalization with Qt documentation.</p>
<p><b>ConsoleExtension</b></p>
<p>The console object implements a subset of the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Console">Console API</a>, which provides familiar logging functions, such as <code>console.log()</code>.</p>
<p>The list of functions added is as follows:</p>
<ul>
<li><code>console.assert()</code></li>
<li><code>console.debug()</code></li>
<li><code>console.exception()</code></li>
<li><code>console.info()</code></li>
<li><code>console.log()</code> (equivalent to <code>console.debug()</code>)</li>
<li><code>console.error()</code></li>
<li><code>console.time()</code></li>
<li><code>console.timeEnd()</code></li>
<li><code>console.trace()</code></li>
<li><code>console.count()</code></li>
<li><code>console.warn()</code></li>
<li><code>print()</code> (equivalent to <code>console.debug()</code>)</li>
</ul>
<p>For more information, see the Console API documentation.</p>
<p><b>GarbageCollectionExtension</b></p>
<p>The <code>gc()</code> function is equivalent to calling <a href="qjsengine.html#collectGarbage">collectGarbage</a>().</p>
<p>The Extensions type is a typedef for <a href="../qtcore/qflags.html">QFlags</a>&lt;Extension&gt;. It stores an OR combination of Extension values.</p>
<!-- @@@Extension -->
</div>
<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-1"><a name="QJSEngine-1"></a>QJSEngine::<span class="name">QJSEngine</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></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"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>program</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></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 -->
<!-- $$$installExtensions[overload1]$$$installExtensionsExtensionsconstQJSValue& -->
<h3 class="fn" id="installExtensions"><a name="installExtensions"></a><span class="type">void</span> QJSEngine::<span class="name">installExtensions</span>(<span class="type"><a href="qjsengine.html#Extension-enum">Extensions</a></span> <i>extensions</i>, const <span class="type"><a href="qjsvalue.html">QJSValue</a></span> &amp;<i>object</i> = QJSValue())</h3>
<p>Installs JavaScript <i>extensions</i> to add functionality that is not available in a standard ECMAScript implementation.</p>
<p>The extensions are installed on the given <i>object</i>, or on the <a href="qjsengine.html#globalObject">Global Object</a> if no object is specified.</p>
<p>Several extensions can be installed at once by <code>OR</code>-ing the enum values:</p>
<pre class="cpp">

  installExtensions(<span class="type"><a href="qjsengine.html#QJSEngine">QJSEngine</a></span><span class="operator">::</span>TranslationExtension <span class="operator">|</span> <span class="type"><a href="qjsengine.html#QJSEngine">QJSEngine</a></span><span class="operator">::</span>ConsoleExtension);

</pre>
<p>This function was introduced in  Qt 5.6.</p>
<p><b>See also </b><a href="qjsengine.html#Extension-enum">Extension</a>.</p>
<!-- @@@installExtensions -->
<!-- $$$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"><a href="../qtcore/qtglobal.html#uint-typedef">uint</a></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 -->
<!-- $$$newQMetaObject[overload1]$$$newQMetaObjectconstQMetaObject* -->
<h3 class="fn" id="newQMetaObject"><a name="newQMetaObject"></a><span class="type"><a href="qjsvalue.html">QJSValue</a></span> QJSEngine::<span class="name">newQMetaObject</span>(const <span class="type"><a href="../qtcore/qmetaobject.html">QMetaObject</a></span> *<i>metaObject</i>)</h3>
<p>Creates a JavaScript object that wraps the given <a href="../qtcore/qmetaobject.html">QMetaObject</a> The <i>metaObject</i> must outlive the script engine. It is recommended to only use this method with static metaobjects.</p>
<p>When called as a constructor, a new instance of the class will be created. Only constructors exposed by <a href="../qtcore/qobject.html#Q_INVOKABLE">Q_INVOKABLE</a> will be visible from the script engine.</p>
<p>This function was introduced in  Qt 5.8.</p>
<p><b>See also </b><a href="qjsengine.html#newQObject">newQObject</a>() and <a href="qjsengine.html#qobject-integration">QObject Integration</a>.</p>
<!-- @@@newQMetaObject -->
<!-- $$$newQMetaObject$$$newQMetaObject -->
<h3 class="fn" id="newQMetaObject-1"><a name="newQMetaObject-1"></a><span class="type"><a href="qjsvalue.html">QJSValue</a></span> QJSEngine::<span class="name">newQMetaObject</span>()</h3>
<p>Creates a JavaScript object that wraps the static <a href="../qtcore/qmetaobject.html">QMetaObject</a> associated with class <code>T</code>.</p>
<p>This function was introduced in  Qt 5.8.</p>
<p><b>See also </b><a href="qjsengine.html#newQObject">newQObject</a>() and <a href="qjsengine.html#qobject-integration">QObject Integration</a>.</p>
<!-- @@@newQMetaObject -->
<!-- $$$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"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>object</i>)</h3>
<p>Creates a JavaScript object that wraps the given <a href="../qtcore/qobject.html">QObject</a> <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 <a href="../qtcore/qobject.html">QObject</a>'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>().</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"><a href="../qtcore/qobject.html#QObject">QObject</a></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 <a href="../qtcore/qobject.html">QObject</a> 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> 2017 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>