|Home | Tutorial | Classes | Functions | Qt Scripter | Language | Library | Qt API | QSA Articles Qt Script for Applications

Text Edit Example

This Text Edit example displays a text editor with the user interface written in pure C++.

The example adds the mainwindow of the application as an application object. This makes all the signals, slots and properties of the application's mainwindow and its children scriptable. Please note that this is bad practise for more complex applications, because it makes too much of the application's internal functionality available to script programmers. However, it is a simple solution that may be suitable for some applications.

The text edit also demonstrates the use of Qt , which is QSAD with the GUI builder functionality switched off. This allows the end user to create, edit and debug scripts using the IDE but does not allow them to create dialogs.

Text edit also shows how to make a non QObject class available to Qt Script. Consequently, it should be possible for the script writer to implement a syntax highlighter which works on the current editor. Qt already provides a class called QSyntaxHighlighter. To make this class available, we implement a class called SyntaxHighlighter which inherits QObject and QSyntaxHighlighter. We implement an interface (public slots and signals) which makes the class scriptable in the \cSyntaxHighlighter class.

To allow the script writer to instantiate a syntax highlighter, the class is made available to Qt Script where the class ConstructorFactory inherits QSObjectFactory.

The text edit example already comes with one syntax highlighter implemented in Qt Script. It is called DiffHighlighter and it highlights uniformed diffs.

See also QSA Examples.


Copyright © 2001-2003 TrolltechTrademarks
QSA version 1.0.0-beta2