|Home | Tutorial | Classes | Functions | QSA Developer | Language | Library | Qt API | QSA Articles | Qt Script for Applications | ![]() |
The QSInterpreter class provides the public API for Qt Script for Applications script engine. More...
#include <qsinterpreter.h>
The QSInterpreter class provides the public API for Qt Script for Applications script engine.
This class (implemented in libqsa) provides the functionality required to make Qt/C++ applications scriptable with Qt Script.
For convience reasons, a single instance of the QSInterpreter class exists in an application; it is available as QSInterpreter::defaultInterpreter().
Use addObject() to make application objects available to the interpreter for use by scripts. Such objects can be removed from the interpreter's view with removeObject().
A global function can be executed using call(). Any string containing valid Qt Script code can be executed using evaluate(). These two functions do not require a project to be open, but most other functions only work if there is a current project. Even if you don't use the Qt Scripter, it is suggested to use a scripting project, only for very simple cases, where nothing more than evaluating a simple piece of code is needed, it makes sense to work without a project.
If an error occurs, e.g. during the execution of a script, the error() signal is emitted. The error behavior depends on the errorMode() which is set with setErrorMode().
The list of functions available in a particular class is available from functionsOf(), and the list of global functions is returned by globalFunctions(). To introspect variables and classes in a context, use classesOf() and variablesOf().
See the Manual for more explanation and examples.
The ErrorMode describes what should happen when an error occurs while parsing or executing script code.
* If there is no project open, Qt Scripter can and will not be invoked, so you will need to handle the error() signal yourself or only get a notification message box, if the errorMode() is something else than Nothing.
Currently, only one instance of the class QSInterpreter may exist at any one time. You can access this instance with QSInterpreter::defaultInterpreter().
project specifies the QSProject, which this interpreter will work on.
Makes the QObject o available to the scripting engine. All child objects of o are made available too.
If no object in the parent hierarchy of o has been added via addObject() yet, o will be made available as a toplevel object to the programmer and will be accessible via Application.object_name (where object_name is the value of o's QObject::name() property).
If an object in the parent hierarchy of o has been made available via addObject() already, o will not be made available as a toplevel object. It is accessible then through parent1.parent2.object_name in the scripting language, given that parent1 has been made available via addObject() previously. The reason to make an object available like this, even though it is not made available as a toplevel object, is so that code can be added in in the context of that object. See setObjectSource().
Warning: Every object passed to this function must have a name.
Example: scriptbutton/main.cpp.
Example:
QSInterpreter::defaultInterpreter()->addSignalHandler( Form1.okButton, SIGNAL( clicked() ), document, "startCalculation" );
See also removeSignalHandler().
Example:
QSInterpreter::defaultInterpreter()->addSignalHandler( Form1.okButton, SIGNAL( clicked() ), "classA.obj.calculate" );
See also removeSignalHandler().
Functions which were passed to evaluate() in previous calls or which are defined in the current project, can be called from this function.
If context is 0 (default), the function is called in the global scope. If a context is given, the function is called in the scope of that object.
The functions openIDE() and closeIDE() clear the interpreter and re-evaluate the current project, meaning the code which has been passed previously into evaluate() gets lost when calling one of these functions.
See also functionsOf(), classesOf(), and variablesOf().
See also functionsOf(), classes(), globalClasses(), and variablesOf().
See also functionsOf(), classes(), globalClasses(), and variablesOf().
This function does not clear the application objects. Use clearObjects() to do that.
See also removeObject().
(This function will automatically create the interpreter if it doesn't already exist.)
Examples: spreadsheet/addscriptdialog.ui.h and spreadsheet/spreadsheet.ui.h.
This signal is emitted if an error occurs when running or parsing a script. message contains the error message from the interpreter, filename the filename (if known) where the error occured, and lineNumber the line number at which the error occured..
This signal is emitted if an error occurs when running or parsing a script. message contains the error message from the interpreter, context a pointer to the QObject context in which the error occured or 0, if the context is the global context, filename the filename (if known) where the error occured, and lineNumber the line number at which the error occured..
Returns what should happen when an error occurs. See the "errorMode" property for details.
This function executes the code passed in as code. The code can use and reference code (functions, classes, variables, etc.) which have been passed to this function previously or which are defined in the current project. Also application objects, which have been added via addObject() can be accessed.
If context is 0 (default), the code is executed as global code. If a context is given, the code is executed in the context of that object.
The functions openIDE() and closeIDE() clear the interpreter and re-evaluate the current project, meaning the code which has been passed previously into evaluate gets lost when calling one of these functions.
context can be fully qualified.
If includeSignature is FALSE (the default), no signature is appended to the function name. If includeSignature is TRUE then each name returned will be of the form:
functionName( typeOfArg1, typeOfArg2, ... )
See also globalFunctions(), classes(), classesOf(), and variablesOf().
If includeSignature is FALSE (the default), no signature is appended to the function name. If includeSignature is TRUE then each name returned will be of the form:
functionName( typeOfArg1, typeOfArg2, ... )
See also globalFunctions(), classes(), classesOf(), and variablesOf().
See also functionsOf(), classes(), classesOf(), and variablesOf().
If includeSignature is FALSE (the default), no signature is appended to the function name. If includeSignature is TRUE then each name returned will be of the form:
functionName( typeOfArg1, typeOfArg2, ... )
See also functionsOf(), classes(), classesOf(), and variablesOf().
Example: spreadsheet/addscriptdialog.ui.h.
See also functionsOf(), classes(), classesOf(), and variablesOf().
Example: spreadsheet/addscriptdialog.ui.h.
See also clearObjects().
See also addSignalHandler().
See also addSignalHandler().
Sets what should happen when an error occurs to m. See the "errorMode" property for details.
See also functionsOf(), classes(), classesOf(), and globalFunctions().
See also functionsOf(), classes(), classesOf(), and globalFunctions().
This property holds what should happen when an error occurs.
Set this property's value with setErrorMode() and get this property's value with errorMode().
This file is part of Qt Script for Applications, copyright © 2001-2003 Trolltech. All Rights Reserved.
Copyright © 2001-2003 Trolltech | Trademarks | QSA version 1.0.0-beta2
|