|Home | Tutorial | Classes | Functions | QSA Workbench | Language | Qt API | QSA Articles | Qt Script for Applications | ![]() |
The QSInterpreter class provides the public API for the Qt Script for Applications script engine. More...
#include <qsinterpreter.h>
The QSInterpreter class provides the public API for the 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 convenience reasons, a single instance of the QSInterpreter class exists in an application; it is available as QSInterpreter::defaultInterpreter().
The functions evaluate(), call(), addTransientObject(), and clear() provide the basic functionality of the interpreter. Any string containing valid Qt Script code can be executed using evaluate(), and any state built up during evaluation will be kept between calls. The function call() can be used to call script functions from C++. The function addTransientObject() will add an object to the interpreter for a time. Calling clear() will clear the state of the interpreter and remove all transient objects.
The function checkSyntax() provides syntax checking without having to execute the context of the code.
QSInterpreter provides several functions for script introspection. These functions are: classes(), functions(), and variables().
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(). When the interpreter stops execution because of an error, the hadError(), errorMessage(), and stackTrace() functions can be used to provide error information.
See the Manual for more explanations and examples.
The ClassFlags enum describes which method should be used for class introspection.
The ErrorMode enum describes what happens when an error occurs while parsing or executing script code.
The FunctionFlags enum describes matching rules and formatting for function introspection.
The parent and name parameters are passed on to the QObject base class.
There's a default instance accessible with QSInterpreter::defaultInterpreter().
Using this function will clear the state of the interpreter.
Transient objects added to the interpreter are not persistent, meaning that when the interpreter is cleared, they are also removed. Also, when the project is re-evaluated the interpreter is cleared and these objects are removed.
Use QSProject::addObject() to add persistent objects to the interpreter.
See also QSProject::addObject().
Example:
interpreter->addTransientSignalHandler( myButton, SIGNAL( clicked() ), "classA.obj.calculate" );
See also removeTransientSignalHandler().
Using this function will clear the state of the interpreter.
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.
Interpreters that belong to a project are subject to re-evaluation, since the code which has been passed previously into evaluate() gets lost when calling one of these functions. This happens when the project or the scripts in it are modified.
If flags is AllClasses (default), all classes in the interpreter are returned, including those declared in object contexts. If flags is GlobalClasses, only classes declared in the global context are returned.
See also functions() and variables().
See also functions() and variables().
See also functions() and variables().
When the interpreter is cleared, all declarations parsed using the function QSInterpreter::evaluate() are removed. The state of all variables will also be cleared.
Clearing the interpreter will also remove the non-persistant objects. Non persistant objects are those added with the function QSInterpreter::addObject() or by evaluating code in the context of a QObject using QSInterpreter::evaluate();
This function does not clear persistent application objects added by the function QSProject::addObject().
The default interpreter runs without a project.
This function will automatically create the interpreter if it doesn't already exist.
This signal is emitted if an error occurs when running or parsing a script. message contains the error message from the interpreter, scriptName contains the scriptname (if known) of where the error occurred, and lineNumber contains the line number at which the error occurred.
This signal is emitted if an error occurs when running or parsing a script. message contains the error message from the interpreter, context is a pointer to the QObject context in which the error occurred or 0, if the context is the global context, scriptName contains the scriptName (if known) of where the error occurred, and lineNumber contains the line number at which the error occurred.
Returns what occurs when there is an error:. 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, if present. 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.
Interpreters that belong to a project are subject to re-evaluation, since the code which has been passed previously into evaluate() gets lost when calling one of these functions. This happens when the project or the scripts in it are modified.
scriptName can be used for error reporting and debugging.
If flags does not include FunctionSignatures (default), only the function names are returned. If flags does include FunctionSignatures, then each function name returned will be on the following form:
functionName( typeOfArg1, typeOfArg2, ... )
See also classes() and variables().
context can be fully qualified.
If flags does not include FunctionSignatures (default), only the function names are returned. If flags does include FunctionSignatures, then each function name returned will be on the following form:
functionName( typeOfArg1, typeOfArg2, ... )
If flags includes IncludeMemberFunctions and context represents a class declared in script, this function will return all static and non static functions; otherwise only returns static functions.
See also classes() and variables().
If flags does not include FunctionSignatures (default), only the function names are returned. If flags does include FunctionSignatures, then each function name returned will be on the following form:
functionName( typeOfArg1, typeOfArg2, ... )
See also classes() and variables().
See also addTransientSignalHandler().
Sets what occurs when there is an error: to m. See the "errorMode" property for details.
See also functions() and classes().
See also functions() and classes().
See also functions() and classes().
This property holds what occurs when there is an error:.
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
|