|Home | Tutorial | Classes | Functions | QSA Workbench | 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(), and 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 using 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 createEditor(), and can be queried using the editors(), editor(), and 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 situation.
Several actions in the interpreter will trigger re-evaluation of the project; consequently, the interpreter will be cleared and the scripts re-evaluated. Such actions include modifying scripts and removing objects. For this reason it is unwise to have executing script code (such as calling application functionality) outside of functions when using a QSProject. Non-executing script code (such as declaration of global variables) is safe.
The addSignalHandler() and removeSignalHandler() functions can be used to connect and disconnect signals and slots from C++ to Qt Script.
Note on threading; The QSProject class cannot be used outside the GUI thread.
See the Manual for more explanations and examples.
See also QSScript, QSEditor, and QSInterpreter.
The StorageMode enum describes the format of the project files when they are stored with QSProject::save()
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, assuming 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 persistent. This means that when the interpreter is cleared, either by calling QSInterpreter::clear() or by modifying the scripts, these objects will remain 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.
Note on threading; If the interpreter is running in the non-GUI thread, object cannot be a QWidget subclass.
Warning: Every object passed to this function must have a unique 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 deleted.
See also addObject(), removeObject(), object(), and QSInterpreter::addTransientObject().
For each editor that is changed, commit() is called, propagating the changes in the editor into 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 will occur, for example, when a user 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 error() signal 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 the objects are already known to the interpreter via QSProject::addObject() or QSInterpreter::addTransientObject().
If an error occurs while running or parsing the script, actions according to the errorMode() are taken and the error() signal 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.
This signal is emitted whenever the project has changed in such a way that it is out of sync with the interpreter and needs to be re-evaluated before the interpreter is used.
This signal is emitted whenever the project has been evaluated and the interpreter back in sync with the scripts in the project.
Note that only persistent objects 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 be modified.
See also editorsModified() and commitEditorContents().
The default for projectFile is QString::null, in which case the filename used during load will be 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().
See also StorageMode.
See also StorageMode.
This file is part of Qt Script for Applications, copyright © 2001-2004 Trolltech. All Rights Reserved.
Copyright © 2001-2006 Trolltech | Trademarks | QSA version 1.1.5
|