TextDocument QML Type

A wrapper around TextEdit's backing QTextDocument. More...

Import Statement: import QtQuick
Instantiates: QQuickTextDocument

Properties

Signals

Methods

  • void save() (since 6.7)
  • void saveAs(url url) (since 6.7)

Detailed Description

To load text into the document, set the source property. If the user then modifies the text and wants to save the same document, call save() to save it to the same source again (only if it's a local file). Or call saveAs() to save it to a different file.

This class cannot be instantiated in QML, but is available from TextEdit::textDocument.

Note: All loading and saving is done synchronously for now. This may block the UI if the source is a slow network drive. This may be improved in future versions of Qt.

Note: This API is considered tech preview and may change in future versions of Qt.

Property Documentation

modified : bool [since 6.7]

This property holds whether the document has been modified by the user since the last time it was loaded or saved. By default, this property is false.

As with QTextDocument::modified, you can set the modified property: for example, set it to false to allow setting the source property to a different URL (thus discarding the user's changes).

This property was introduced in Qt 6.7.

See also QTextDocument::modified.


source : url [since 6.7]

QQuickTextDocument can handle any text format supported by Qt, loaded from any URL scheme supported by Qt.

The URL may be absolute, or relative to the URL of the component.

The source property cannot be changed while the document's modified state is true. If the user has modified the document contents, you should prompt the user whether to save(), or else discard changes by setting modified = false before setting the source property to a different URL.

This property was introduced in Qt 6.7.

See also QTextDocumentWriter::supportedDocumentFormats().


Signal Documentation

error(string message)

This signal is emitted when an error message (translated string) should be presented to the user, for example with a MessageDialog.

Note: The corresponding handler is onError.


Method Documentation

[since 6.7] void save()

Saves the contents to the same file and format specified by source.

Note: You can save only to a file on a mounted filesystem.

This method was introduced in Qt 6.7.

See also source and saveAs().


[since 6.7] void saveAs(url url)

Saves the contents to the file and format specified by url.

The file extension in url specifies the file format (as determined by QMimeDatabase::mimeTypeForUrl()).

Note: You can save only to a file on a mounted filesystem.

This method was introduced in Qt 6.7.

See also source and saveAs().