/usr/share/qt5/doc/qtqml/qtjavascript.html is in qtdeclarative5-doc-html 5.2.1-3ubuntu15.
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 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qtjavascript.qdoc -->
<title>Making Applications Scriptable | QtQml 5.2</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.2</li>
<li><a href="qtqml-index.html">Qt QML</a></li>
<li>Making Applications Scriptable</li>
<li id="buildversion">
Qt 5.2.1 Reference Documentation</li>
</ul>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#scripting-classes">Scripting Classes</a></li>
<li class="level1"><a href="#basic-usage">Basic Usage</a></li>
<li class="level1"><a href="#making-a-qobject-available-to-the-script-engine">Making a QObject Available to the Script Engine</a></li>
</ul>
</div>
<h1 class="title">Making Applications Scriptable</h1>
<span class="subtitle"></span>
<!-- $$$qtjavascript.html-description -->
<div class="descr"> <a name="details"></a>
<p>Qt provides support for application scripting with JavaScript. The following guides and references cover aspects of programming with JavaScript and Qt.</p>
<a name="scripting-classes"></a>
<h2>Scripting Classes</h2>
<p>The following classes add scripting capabilities to Qt applications.</p>
<table class="annotated">
<tr class="odd topAlign"><td class="tblName"><p><a href="qjsengine.html">QJSEngine</a></p></td><td class="tblDescr"><p>Environment for evaluating JavaScript code</p></td></tr>
<tr class="even topAlign"><td class="tblName"><p><a href="qjsvalue.html">QJSValue</a></p></td><td class="tblDescr"><p>Acts as a container for Qt/JavaScript data types</p></td></tr>
<tr class="odd topAlign"><td class="tblName"><p><a href="qjsvalueiterator.html">QJSValueIterator</a></p></td><td class="tblDescr"><p>Java-style iterator for QJSValue</p></td></tr>
</table>
<a name="basic-usage"></a>
<h2>Basic Usage</h2>
<p>To evaluate script code, you create a <a href="qjsengine.html">QJSEngine</a> and call its evaluate() function, passing the script code (text) to evaluate as argument.</p>
<pre class="cpp"><span class="type"><a href="qjsengine.html">QJSEngine</a></span> engine;
qDebug() <span class="operator"><</span><span class="operator"><</span> <span class="string">"the magic number is:"</span> <span class="operator"><</span><span class="operator"><</span> engine<span class="operator">.</span>evaluate(<span class="string">"1 + 2"</span>)<span class="operator">.</span>toNumber();</pre>
<p>The return value will be the result of the evaluation (represented as a <a href="qjsvalue.html">QJSValue</a> object); this can be converted to standard C++ and Qt types.</p>
<p>Custom properties can be made available to scripts by registering them with the script engine. This is most easily done by setting properties of the script engine's <i>Global Object</i>:</p>
<pre class="cpp">engine<span class="operator">.</span>globalObject()<span class="operator">.</span>setProperty(<span class="string">"foo"</span><span class="operator">,</span> <span class="number">123</span>);
qDebug() <span class="operator"><</span><span class="operator"><</span> <span class="string">"foo times two is:"</span> <span class="operator"><</span><span class="operator"><</span> engine<span class="operator">.</span>evaluate(<span class="string">"foo * 2"</span>)<span class="operator">.</span>toNumber();</pre>
<p>This places the properties in the script environment, thus making them available to script code.</p>
<a name="making-a-qobject-available-to-the-script-engine"></a>
<h2>Making a QObject Available to the Script Engine</h2>
<p>Any QObject-based instance can be made available for use with scripts.</p>
<p>When a QObject is passed to the <a href="qjsengine.html#newQObject">QJSEngine::newQObject</a>() function, a Qt Script wrapper object is created that can be used to make the QObject's signals, slots, properties, and child objects available to scripts.</p>
<p>Here's an example of making an instance of a QObject subclass available to script code under the name <tt>"myObject"</tt>:</p>
<pre class="cpp"><span class="type"><a href="qjsengine.html">QJSEngine</a></span> engine;
<span class="type">QObject</span> <span class="operator">*</span>someObject <span class="operator">=</span> <span class="keyword">new</span> MyObject;
<span class="type"><a href="qjsvalue.html">QJSValue</a></span> objectValue <span class="operator">=</span> engine<span class="operator">.</span>newQObject(someObject);
engine<span class="operator">.</span>globalObject()<span class="operator">.</span>setProperty(<span class="string">"myObject"</span><span class="operator">,</span> objectValue);</pre>
<p>This will create a global variable called <tt>myObject</tt> in the script environment. The variable serves as a proxy to the underlying C++ object. Note that the name of the script variable can be anything; i.e., it is not dependent upon QObject::objectName().</p>
</div>
<!-- @@@qtjavascript.html -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2013 Digia Plc and/or its
subsidiaries. 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> Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|