summaryrefslogtreecommitdiffstats
path: root/doc/src/examples/helloscript.qdoc
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-03-23 09:18:55 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2009-03-23 09:18:55 (GMT)
commite5fcad302d86d316390c6b0f62759a067313e8a9 (patch)
treec2afbf6f1066b6ce261f14341cf6d310e5595bc1 /doc/src/examples/helloscript.qdoc
downloadQt-e5fcad302d86d316390c6b0f62759a067313e8a9.zip
Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz
Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.bz2
Long live Qt 4.5!
Diffstat (limited to 'doc/src/examples/helloscript.qdoc')
-rw-r--r--doc/src/examples/helloscript.qdoc142
1 files changed, 142 insertions, 0 deletions
diff --git a/doc/src/examples/helloscript.qdoc b/doc/src/examples/helloscript.qdoc
new file mode 100644
index 0000000..5662680
--- /dev/null
+++ b/doc/src/examples/helloscript.qdoc
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example script/helloscript
+ \title Hello Script Example
+
+ The Hello Script example shows the basic use of Qt Script: How to embed
+ a script engine into the application, how to evaluate a script, and how
+ to process the result of the evaluation. The example also shows how to
+ apply internationalization to scripts.
+
+ \snippet examples/script/helloscript/main.cpp 0
+
+ The application will load the script file to evaluate from a resource, so
+ we first make sure that the resource is initialized.
+
+ \snippet examples/script/helloscript/main.cpp 1
+
+ We attempt to load a translation, and install translation functions in the
+ script engine. How to produce a translation is explained later.
+
+ \snippet examples/script/helloscript/main.cpp 2
+
+ A push button is created and exported to the script environment as a
+ global variable, \c button. Scripts will be able to access properties,
+ signals and slots of the button as properties of the \c button script
+ object; the script object acts as a proxy to the C++ button object.
+
+ \snippet examples/script/helloscript/main.cpp 3
+
+ The contents of the script file are read.
+
+ \snippet examples/script/helloscript/helloscript.qs 0
+
+ The script sets the \c text (note that the qTr() function is used to allow
+ for translation) and \c styleSheet properties of the button, and calls the
+ button's \c show() slot.
+
+ \snippet examples/script/helloscript/main.cpp 4
+
+ The script is evaluated. Note that the file name is passed as the
+ (optional) second parameter; this makes it possible for the script engine
+ to produce a meaningful backtrace if something goes wrong, and makes the
+ qTr() function be able to resolve the translations that are associated
+ with this script.
+
+ \snippet examples/script/helloscript/main.cpp 5
+
+ If the result is an Error object (e.g. the script contained a syntax
+ error, or tried to call a function that doesn't exist), we obtain
+ the line number and string representation of the error and display
+ it in a message box.
+
+ \snippet examples/script/helloscript/main.cpp 6
+
+ If the evaluation went well, the application event loop is entered.
+
+ \section1 Translating the Application
+
+ The Qt Script internalization support builds on what Qt already provides
+ for C++; see the \l{Hello tr() Example} for an introduction.
+
+ Since we haven't made the translation file \c helloscript_la.qm, the
+ source text is shown when we run the application ("Hello world!").
+
+ To generate the translation file, run \c lupdate as follows:
+
+ \code
+ lupdate helloscript.qs -ts helloscript_la.ts
+ \endcode
+
+ You should now have a file \c helloscript_la.ts in the current
+ directory. Run \c linguist to edit the translation:
+
+ \code
+ linguist helloscript_la.ts
+ \endcode
+
+ You should now see the text "helloscript.qs" in the top left pane.
+ Double-click it, then click on "Hello world!" and enter "Orbis, te
+ saluto!" in the \gui Translation pane (the middle right of the
+ window). Don't forget the exclamation mark!
+
+ Click the \gui Done checkbox and choose \gui File|Save from the
+ menu bar. The \c .ts file will no longer contain
+
+ \snippet doc/src/snippets/code/doc_src_examples_hellotr.qdoc 3
+
+ but instead will have
+
+ \snippet doc/src/snippets/code/doc_src_examples_hellotr.qdoc 4
+
+ To see the application running in Latin, we have to generate a \c .qm
+ file from the \c .ts file. Generating a \c .qm file can be achieved
+ either from within \e {Qt Linguist} (for a single \c .ts file), or
+ by using the command line program \c lrelease which will produce one \c
+ .qm file for each of the \c .ts files listed in the project file.
+ Generate \c hellotr_la.qm from \c hellotr_la.ts by choosing
+ \gui File|Release from \e {Qt Linguist}'s menu bar and pressing
+ \gui Save in the file save dialog that pops up. Now run the \c helloscript
+ program again. This time the button will be labelled "Orbis, te
+ saluto!".
+*/