Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / doc / src / declarative / qtjavascript.qdoc
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** GNU Free Documentation License
10 ** Alternatively, this file may be used under the terms of the GNU Free
11 ** Documentation License version 1.3 as published by the Free Software
12 ** Foundation and appearing in the file included in the packaging of
13 ** this file.
14 **
15 ** Other Usage
16 ** Alternatively, this file may be used in accordance with the terms
17 ** and conditions contained in a signed written agreement between you
18 ** and Nokia.
19 **
20 **
21 **
22 **
23 **
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27
28 /*!
29     \group qtjavascript
30     \title Scripting Classes and Overviews
31
32     \brief Classes for embedding JavaScript in Qt/C++ applications.
33 */
34
35 /*!
36   \page qtjavascript.html
37 \inqmlmodule QtQuick 2
38   \title Making Applications Scriptable
39   \ingroup frameworks-technologies
40
41   Qt provides support for application scripting with JavaScript.
42   The following guides and references cover aspects of programming with
43   JavaScript and Qt.
44
45   \tableofcontents
46
47   \section1 Scripting Classes
48
49   The following classes add scripting capabilities to Qt applications.
50
51   \annotatedlist qtjavascript
52
53   \section1 Basic Usage
54
55   To evaluate script code, you create a QJSEngine and call its
56   evaluate() function, passing the script code (text) to evaluate
57   as argument.
58
59   \snippet doc/src/snippets/qtjavascript/evaluation/main.cpp 0
60
61   The return value will be the result of the evaluation (represented
62   as a QJSValue object); this can be converted to standard C++
63   and Qt types.
64
65   Custom properties can be made available to scripts by registering
66   them with the script engine. This is most easily done by setting
67   properties of the script engine's \i{Global Object}:
68
69   \snippet doc/src/snippets/qtjavascript/registeringvalues/main.cpp 0
70
71   This places the properties in the script environment, thus making them
72   available to script code.
73
74   \section1 Making a QObject Available to the Script Engine
75
76   Any QObject-based instance can be made available for use with scripts.
77
78   When a QObject is passed to the QJSEngine::newQObject() function,
79   a Qt Script wrapper object is created that can be used to make the
80   QObject's signals, slots, properties, and child objects available
81   to scripts.
82
83   Here's an example of making an instance of a QObject subclass
84   available to script code under the name \c{"myObject"}:
85
86   \snippet doc/src/snippets/qtjavascript/registeringobjects/main.cpp 0
87
88   This will create a global variable called \c{myObject} in the
89   script environment. The variable serves as a proxy to the
90   underlying C++ object. Note that the name of the script variable
91   can be anything; i.e., it is not dependent upon QObject::objectName().
92
93  */