Sharing Code and Dialogs of Scripts between Scripts

Sometimes you have functions, classes or forms in a project that you
would like to be able to use in other scripts. To share these files,
you should save them as packages in a location other than within the
project. For more details about importing packages into scripts and
the Qt Script package paths, please read the Language Reference guide.

Creating Packages in Qt Scripter.

Click File|New|File to open a new file for writing the script. The
Name of File dialog box pops up. Enter the name of the new file and
click OK.

Write your code in the new file you created. Now we need to make a
package to save this file so that it can be shared.

Locate the new file listed in the Projects Overview window. Right
click on the new file name and then click Export as Package on the
contect menu.

The Save As Dialog pops up. Name the file and save it to the location
of your choice. But you have to save the file at a place where it can
found again by Qt Script. Qt Script searches the Qt Script package
paths for packages, so you should save the file under one of these
paths.

If you right click on the file name listed on the Projects Overview
window, you will notice that the item "Package" is checked now,
meaning that it is now a package and not part of the project.

The same approach can be used to export dialogs as packages.

Editing an Existing Package

Editing an existing package is simple and straightforward. Open Qt
Scripter if it is not already open. Click File|Import Package for
Editing. Choose on the package you want to open from the File dialog.

Using a Package

To use a package in a particular project, you must type 'import
packagename' in the source code editor. You have to set the Qt Script
package path. This can be done by setting the environment variable
QTSCRIPT_PACKAGES or by setting the path in the project settings
(Project->Project Settings, Tab [General], edit box "Package
Paths"). For more information about the Qt Script package paths, see
the language reference.




