|Home | Tutorial | Classes | Functions | Qt Scripter | Language | Qt API | QSA Articles | Qt Script for Applications | ![]() |
The QSProject class provides project management over scripts written in Qt Script for Applications. More...
#include <qsproject.h>
The QSProject class provides project management over scripts written in Qt Script for Applications.
The project's interpreter can be accessed through the function interpreter().
Scripts are encapsulated as instances of the class QSScript. QSScript objects are created by using the createScript() functions. It is possible to query the project for scripts using the functions scripts(), scriptNames(), or script().
It is possible to associate a QSScript with a context object, meaning that the script will be evaluated in the context of that object. If a script and an object have the same name, they are grouped together.
Objects are added to the project with addObject() and removed from the project with removeObject(). To query the project's objects, use the object() and objects() functions. Note that objects added to the project become persistant, meaning that when the interpreter is cleared, they will still be scriptable. This is in contrast to objects added to the interpreter through the QSInterpreter::addTransientObject() function, which will not be available after the interpreter is cleared.
A project can be stored on disk and loaded again using the load() and save() functions. It is also possible to write the project to a data buffer that can be used in conjunction with other applications by using the loadFromData() and saveToData() functions.
The project also manages editors for the scripts it holds. Editors can be created using the functions createEditor() and can be queried using the editors(), editor() or activeEditor() functions. When text changes in the interpreter, the editorsModified() signal is emitted. Before the changes are reflected in the script, the commitEditorContents() function must be called. To revert the editors to the code in the scripts use revertEditorContents().
When the editors are committed, the scripts will be out of sync with the state of the interpreter. The scriptsModified() signal is emitted to indicate this occurrence.
Several actions in the interpreter will trigger re-evaluation of the project; consequently, the interpreter will be cleared and the scripts re-evaluated. These actions include modifying scripts and removing objects.
The addSignalHandler() and removeSignalHandler() functions can be used to connect and disconnect signals and slots from C++ to Qt Script.
See the Manual for more explanations and examples.
See also QSScript, QSEditor, and QSInterpreter.
If no object in the parent hierarchy of object has been added via addObject(), object 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 object's QObject::name() property).
If an object in the parent hierarchy of object has been made available via addObject(), object will not be made available as a toplevel object. It is then accessible through parent1.parent2.object_name in the scripting language, given that parent1 has previously been made available via addObject(). The reason to make an object available this way even though it is not made available as a toplevel object, is so that code can be added in the context of that object.
Objects added with this function are made persistent. This means that when the interpreter is cleared, either by calling QSInterpreter::clear() or by modifying the scripts, these objects will still be made available to the scripting engine.
If a script exists in the project that has the same name as object, the script will be evaluated with object as context.
Warning: Every object passed to this function must have a name.
See also QSInterpreter::addTransientObject(), removeObject(), clearObjects(), and object().
Example:
project->addSignalHandler( myButton, SIGNAL( clicked() ), document, "startCalculation" );
See also removeSignalHandler().
Example:
project->addSignalHandler( myButton, SIGNAL( clicked() ), "a.b.startCalculation" );
See also removeSignalHandler().
QSProject does not take ownership of the objects, so the objects are not cleared.
See also addObject(), removeObject(), object(), and QSInterpreter::addTransientObject().
For each editor that is changed, commit() is called, propagating the changes in the editor onto the script it is currently editing.
After a call to commitEditorContents, the project will no longer be modified
See also editorsModified() and revertEditorContents().
If script does not belong to the current project, 0 is returned.
If an editor already exists for the given script, the existing editor is returned.
The context is added to this project's list of objects.
If a script already exists for this context, 0 is returned.
If an object exists in the project with the same name as name, the object is associated with the created script and the script will be evaluated in the context of that object.
If a script already exists with this name, 0 is returned.
This signal is emitted whenever text changes in one of the editors that the project currently manages.
A project enters the modified state when the editors and scripts become out of sync. This is the case when a user simply edits a script in an editor. Before the interpreter is used, this value should be checked and the application should decide to either commit or revert the changes in the editor before the project is evaluated.
See also commitEditorContents() and revertEditorContents().
If an error occurs while running or parsing the script, actions according to the errorMode() are taken and the signal error() is emitted.
After load() is called, functions and classes defined in this project can be called and used through the evaluate() and call() functions.
If the project has signal/slot connections, for example, a form that connects widget signals to Qt Script slots, then the connections are established as part of the open() process.
If an error occurs while running or parsing the script, actions according to the errorMode() are taken and the signal error() is emitted.
After loadFromData() is called, functions and classes defined in this project can be called and used through the evaluate() and call() functions.
If the project has signal/slot connections, for example, a form that connects widget signals to Qt Script slots, then the connections are established as part of the process.
Note that only the persistent projects can be removed with this function. Objects added to the interpreter using QSInterpreter::addTransientObject can not be removed with this function.
If object is the context of a script, the script will also be removed from the project.
See also addObject(), clearObjects(), and object().
See also addSignalHandler().
See also addSignalHandler().
After a call to revertEditorContents, the project will no longer return TRUE from editorsModified()
See also editorsModified() and commitEditorContents().
The default for projectFile is QString::null, in which case the filename used during load was used.
See also load().
This is useful for keeping the project data with a document. For example, you can take the data returned by this function and store it in a document's file. Later, when the document is opened, you can extract the data from the document and pass it to the overload of openFromData() that takes a QByteArray to reconstruct the project.
See also loadFromData().
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-beta5
|