summaryrefslogtreecommitdiffstats
path: root/doc/src/declarative/javascriptblocks.qdoc
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/declarative/javascriptblocks.qdoc')
-rw-r--r--doc/src/declarative/javascriptblocks.qdoc30
1 files changed, 27 insertions, 3 deletions
diff --git a/doc/src/declarative/javascriptblocks.qdoc b/doc/src/declarative/javascriptblocks.qdoc
index 16d0633..155bd6e 100644
--- a/doc/src/declarative/javascriptblocks.qdoc
+++ b/doc/src/declarative/javascriptblocks.qdoc
@@ -94,9 +94,8 @@ Both relative and absolute JavaScript URLs can be imported. In the case of a
relative URL, the location is resolved relative to the location of the
\l {QML Document} that contains the import. If the script file is not accessible,
an error will occur. If the JavaScript needs to be fetched from a network
-resource, the QML document has a "Loading"
-\l {QDeclarativeComponent::status()}{status} until the script has been
-downloaded.
+resource, the component's \l {QDeclarativeComponent::status()}{status} is set to
+"Loading" until the script has been downloaded.
Imported JavaScript files are always qualified using the "as" keyword. The
qualifier for JavaScript files must be unique, so there is always a one-to-one
@@ -143,6 +142,31 @@ As they are shared, stateless library files cannot access QML component instance
objects or properties directly, although QML values can be passed as function
parameters.
+
+\section2 Importing One JavaScript File From Another
+
+If a JavaScript file needs to use functions defined inside another JavaScript file,
+the other file can be imported using the \l {QML:Qt::include()}{Qt.include()}
+function. This imports all functions from the other file into the current file's
+namespace.
+
+For example, the QML code below left calls \c showCalculations() in \c script.js,
+which in turn can call \c factorial() in \c factorial.js, as it has included
+\c factorial.js using \l {QML:Qt::include()}{Qt.include()}.
+
+\table
+\row
+\o {1,2} \snippet doc/src/snippets/declarative/integrating-javascript/includejs/app.qml 0
+\o \snippet doc/src/snippets/declarative/integrating-javascript/includejs/script.js 0
+\row
+\o \snippet doc/src/snippets/declarative/integrating-javascript/includejs/factorial.js 0
+\endtable
+
+Notice that calling \l {QML:Qt::include()}{Qt.include()} imports all functions from
+\c factorial.js into the \c MyScript namespace, which means the QML component can also
+access \c factorial() directly as \c MyScript.factorial().
+
+
\section1 Running JavaScript at Startup
It is occasionally necessary to run some imperative code at application (or