Utils::TextFileFormat Class | Extending Qt Creator Manual
Description: The TextFileFormat class describes the format of a text file and provides autodetection.

- Extending Qt Creator Manual
- QtCreator
- TextFileFormat
- Extending Qt Creator Manual 18.0.2

# Utils::TextFileFormat Class

class Utils::TextFileFormat

The TextFileFormat class describes the format of a text file and provides autodetection. More...

Header: | `#include <TextFileFormat>`

- List of all members, including inherited members

## Public Functions

bool | decode(const QByteArray &data, QString *target) const
void | detectFromData(const QByteArray &data)
Utils::TextFileFormat::ReadResult | readFile(const Utils::FilePath &filePath, const Utils::TextEncoding &fallbackEncoding)
Utils::Result<> | writeFile(const Utils::FilePath &filePath, QString plainText) const

## Static Public Members

QByteArray | decodingErrorSample(const QByteArray &data)

## Detailed Description

The format comprises

- Encoding represented by a the name of a codec
- Presence of an UTF8 Byte Order Marker (BOM)
- Line feed storage convention

The class also provides convenience functions to read text files and return them as strings or string lists and to write out files.

## Member Function Documentation

### bool TextFileFormat::decode(const QByteArray &data, QString *target) const

Returns data decoded to a string, target.

### `[static]` QByteArray TextFileFormat::decodingErrorSample(const QByteArray &data)

Returns a piece of text specified by data suitable as display for an encoding error.

### void TextFileFormat::detectFromData(const QByteArray &data)

Detects the format of text data.

### Utils::TextFileFormat::ReadResult TextFileFormat::readFile(const Utils::FilePath &filePath, const Utils::TextEncoding &fallbackEncoding)

Reads a text file from filePath into a string. It detects the codec to use from the BOM read file contents. If none is set, it uses fallbackEncoding. If the fallback is not set, it uses the text encoding set for the locale.

Returns whether decoding was possible without errors. If an error occurs, it is returned together with a decoding error sample.

### Utils::Result<> TextFileFormat::writeFile(const Utils::FilePath &filePath, QString plainText) const

Writes out a text file to filePath into a string, plainText.

Returns whether decoding was possible without errors.