| Tutorial | Classes | Functions | QSA Developer | Language | Library | Qt API Qt Script for Applications

QSProject Class Reference

The QSProject class provides control over a script project for the Qt Application Script interpreter. More...

#include <qsproject.h>

List of all member functions.

Public Members

Public Slots


Detailed Description

The QSProject class provides control over a script project for the Qt Application Script interpreter.

Qt Script for Applications (QSA) collects sets of functions and classes together in projects. Use open() to access a project, either from a file or from a byte array. If a file is used, QSA will automatically take care of saving user changes. The project's data can be retrieved into a byte array using projectData(). One project is current at any one time; close the current project with clear().

The contents of the current project are available using forms() and classes() which return a list of all the forms and classes respectively.

A new global function can be added with addFunction(); this function can also invoke QSA Developer if required. QSA Developer is invoked with openDeveloper() and closed with closeDeveloper().

If QSA Developer is too complex for your application (even with the GUI builder functionality and/or the debugger switched off), you can use QSEditor to create a source code editor for Qt Script (with syntax highlighting, completion, auto indentation, etc), which can be embedded into your application user interface.

See the Manual for more explanation and examples.


Member Type Documentation

QSProject::DeveloperFlags

The DeveloperFlags describe in which mode QSA Developer is opened.


Member Function Documentation

void QSProject::addForm ( const QString & fileName ) [slot]

Loads the form fileName and adds it to the project.

See also removeForm().

bool QSProject::addFunction ( const QString & functionName, const QString & functionBody = QString::null, bool openDeveloper = TRUE ) [slot]

A function called functionName is added to the current project. The name must match the regular expression /^[A-Za-z_][A-Za-z_0-9]*$/.

The code for the function can be passed in the functionBody parameter. If openDeveloper is TRUE (the default), then QSA Developer will be invoked so that the user can edit this function. If functionBody was specified its text will appear in the editor; if the functionBody is empty a new empty function will be created. If the function functionName already exists in the project and openDeveloper is TRUE, QSA Developer will be invoked showing the already existing function in the editor (and any functionBody will be discarded).

This function returns TRUE on success (i.e. the functionName was valid); otherwise returns FALSE.

If there is no project currently open this function does nothing.

void QSProject::addSource ( const QString & code, const QString & fileName, bool append = FALSE ) [slot]

Adds the code code under the name fileName to the project as global code

If there has been added code already under the name fileName, code is appended to this code if append is TRUE, otherwise the currently set code is replaced with code.

See also removeSource().

void QSProject::closeDeveloper () [slot]

Closes QSA Developer, if it is currently open.

If there is no project currently open this function does nothing.

This function clears the interpreter, so code which has been passed into previous evaluate() calls will be lost.

QString QSProject::formSource ( const QString & formName ) const

Returns the code for the form called formName

See also forms() and formXML().

QString QSProject::formXML ( const QString & formName ) const

Returns the XML GUI description of the form called formName

See also forms() and formSource().

QStringList QSProject::forms () const

Returns all names of the forms of the project.

See also formSource() and formXML().

void QSProject::open ( const QString & scriptProject ) [slot]

Opens and parses the Qt Script for Applications script contained in the file, scriptProject. This overload of open() takes care of saving the project to the specified filename automatically. If an error occurs while running or parsing the script, actions according to the errorMode() are taken and the signal error() is emitted.

After open() is called, functions, classes and forms defined in this project can be called and used using evaluate() and call().

If the project has signal/slot connections (for example, a form that connects widget signals to Qt Script slots), then these connections are established as part of the open() process.

The project always stops when QSA Developer is opened, and continues when QSA Developer is closed.

void QSProject::open ( const QByteArray & projectData, const QString & projectName ) [slot]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Reads and parses the Qt Script for Applications script from the projectData QByteArray. projectName must be specified.

If an error occurs while running or parsing the script, the error() signal is emitted, and further action may occur depending on the errorMode().

After open() is called, functions, classes and forms defined in this project can be called and used inside call() and evaluate() calls.

If the project has signal/slot connections (for example, a form that connects widget signals to Qt Script slots), then these connections are established as part of the open() process.

The project always stops when the QSA Developer is invoked, and continues when the QSA Developer is closed.

void QSProject::openDeveloper ( int flags = FullDeveloper ) [slot]

Opens QSA Developer with the current scripting project (if there is one open), so that the project can be edited and debugged.

flags is a value which can contains values of DeveloperFlags or'd together.

If there is no project currently open this function does nothing.

This function clears the interpreter, so code which has been passed into previous evaluate() calls will be lost.

If you created QSEditors, the QSA Developer is always opened with read only editors, even if EditableEditor is part of flags, so that the QSA Developer can be used for debugging, but not editing.

QByteArray QSProject::projectData () const

Returns the whole project as a data block (QByteArray).

This is useful for keeping the project data with a document. For example, you could take the data returned by this function and store it in a document's file. Later, when the document was opened, you could extract this data from the document and pass it to the overload of open() that takes a QByteArray to reconstruct the project.

void QSProject::removeForm ( const QString & fileName ) [slot]

Removes the form which was added under the filename fileName.

See also addForm().

void QSProject::removeSource ( const QString & fileName ) [slot]

Removes the code which was added under the filename fileName.

See also addSource().

void QSProject::reset () [slot]

Normally this function doesn't need to be called, since it is called automatically by the relevant functions (e.g. open(), call(), execute(), etc.). This function is useful in the case where an error has occurred and the script must be run again to reestablish the signal/slot connections between Qt and the script.

QStringList QSProject::scriptFiles () const

Returns a list for all files in this project

QString QSProject::source ( const QString & fileName ) const

Returns the source of the file fileName in this project

This file is part of Qt Script for Applications, copyright © 2001-2002 Trolltech. All Rights Reserved.


Copyright © 2001-2002 TrolltechTrademarks
QSA version 1.0.0-beta1