Qt 5.9 | Qt Quick Controls | Qt Quick Controls Examples | Qt Quick Controls - Text Editor Example

Qt 5.9.2 Reference Documentation

# Qt Quick Controls - Text Editor Example

The Text Editor Example presents a sample HTML file using the TextArea control, preserving the HTML formatting. It uses a C++ class to handle the document by providing options to open, format, and edit. The app also lets you open and edit a plain text files.

The C++ class, DocumentHandler, extends QObject and is registered as a QML type under the namespace, "`org.qtproject.example 1.0`".

The following snippets show how the type is registered under a namespace and later imported by main.qml.

QML type registration:

      #include <QtQml/qqml.h>
      ...
      qmlRegisterType<DocumentHandler>("org.qtproject.example", 1, 0, "DocumentHandler");
      ...

QML namespace import:

      import org.qtproject.example 1.0

For more information about registering C++ classes as QML types, see Defining QML Types from C++.

## Running the Example

To run the example from Qt Creator, open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example.

Files:

- texteditor/qml/ToolBarSeparator.qml
- texteditor/qml/main.qml
- texteditor/src/documenthandler.cpp
- texteditor/src/documenthandler.h
- texteditor/src/main.cpp
- texteditor/resources.qrc
- texteditor/texteditor.pro