本页内容

QTextEncoder Class

QTextEncoder 类提供了一个基于状态的编码器。更多内容...

头文件: #include <QTextEncoder>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
target_link_libraries(mytarget PRIVATE Qt6::Core5Compat)
qmake: QT += core5compat

注意:该类中的所有函数均为可重入函数。

公共函数

QTextEncoder(const QTextCodec *codec)
QTextEncoder(const QTextCodec *codec, int flags)
~QTextEncoder()
QByteArray fromUnicode(const QString &str)
QByteArray fromUnicode(QStringView str)
QByteArray fromUnicode(const QChar *uc, int len)

详细说明

文本编码器使用特定的编解码器,将文本从 Unicode 转换为编码文本格式。

该编码器将 Unicode 转换为另一种格式,并记住调用之间所需的任何状态。

另请参阅 QTextCodec::makeEncoder() 和QTextDecoder 。

成员函数文档

[explicit] QTextEncoder::QTextEncoder(const QTextCodec *codec)

根据给定的codec 构建一个文本编码器。

[explicit] QTextEncoder::QTextEncoder(const QTextCodec *codec, int flags)

根据给定的codec 和转换规则flags 构建一个文本编码器。

[noexcept] QTextEncoder::~QTextEncoder()

破坏了编码器。

QByteArray QTextEncoder::fromUnicode(const QString &str)

将 Unicode 字符串str 转换为编码后的QByteArray 。

QByteArray QTextEncoder::fromUnicode(QStringView str)

将 Unicode 字符串str 转换为编码后的QByteArray 。

这是一个重载函数。

QByteArray QTextEncoder::fromUnicode(const QChar *uc, int len)

将len 字符(而非字节)从uc 转换,并将结果存储在QByteArray 中。

这是一个重载函数。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.