| Tutorial | Classes | Functions | QSA Developer | Language | Library | Qt API | Qt Script for Applications | ![]() |
The Simplescript example shows the usage of QSA without using the Qt Scripter IDE. Instead, it uses the QSA editor component QSEditor for script editing. The main window contains the code editor for users to enter their script code. Below the code editor is a group box called PlayGround which is exposed as an application object so that the script writer can access the PlayGround and all the sub-widgets from the script. The \Button{Call Function} button, located at the bottom right of the editor, opens a dialog so that the user can choose which script function to execute.
QSEditor can be used as QScript Editor if you don't want to use Qt Scripter, but still want to have a more advanced editing component than a plain text editor. QSEditor provides syntax highlight, auto-indentation, code completion, paranthesis matching, and function folding.
All the code in this example is executed in the context of PlayGround.
The exposed application objects do not offer any API in addition to the Qt API.
There are two example functions implemented in the script code. The first function, parseXML(), opens a file dialog and allows the user to choose an XML file. The function then parses this XML file using DOM and displays the result hierarchically in the listview in PlayGround. The parseXML() function uses a private helper function, insertNode(), which is also implemented in the script.
The second example function is connectSliderAndLCDNumber(). This function shows a way of connecting signals and slots in Qt Script( it connects the slider in the PlayGround to the LCD number). This function also opens a message box.
To add a new function, you can simply write it into the editor. For example:
function setText() { this.button1.text = "It works!" }
If you now call this function with the \Button{Call Function} button, the text of the first push button in the PlayGround will change to "It Works!".
See also QSA Examples.
Copyright © 2001-2002 Trolltech | Trademarks | QSA version 1.0.0-beta1
|