diff options
author | David Boddie <david.boddie@nokia.com> | 2010-12-15 13:16:24 (GMT) |
---|---|---|
committer | David Boddie <david.boddie@nokia.com> | 2010-12-15 13:16:24 (GMT) |
commit | 1c1d3e79e1b7cb2cdffaee38a98bc777e3a7b961 (patch) | |
tree | 5c33473950b22db0a0eb9c230005cd8e7f251538 /doc/src/declarative/javascriptblocks.qdoc | |
parent | cace8e6a9f00ee478dfe63a7fa6959056cfe7e8a (diff) | |
parent | 0c6780c39d18a4fd06b9bed94400de365a518c45 (diff) | |
download | Qt-1c1d3e79e1b7cb2cdffaee38a98bc777e3a7b961.zip Qt-1c1d3e79e1b7cb2cdffaee38a98bc777e3a7b961.tar.gz Qt-1c1d3e79e1b7cb2cdffaee38a98bc777e3a7b961.tar.bz2 |
Merge branch '4.7' into mimir
Diffstat (limited to 'doc/src/declarative/javascriptblocks.qdoc')
-rw-r--r-- | doc/src/declarative/javascriptblocks.qdoc | 30 |
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 |