QTextDecoder Class

QTextDecoder 类提供了一个基于状态的解码器。更多

Header: #include <QTextDecoder>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
target_link_libraries(mytarget PRIVATE Qt6::Core5Compat)
qmake: QT += core5compat

注意:该类中的所有函数都是可重入的

公共函数

QTextDecoder(const QTextCodec *codec)
QTextDecoder(const QTextCodec *codec, int flags)
~QTextDecoder()
QString toUnicode(const char *chars, int len)
QString toUnicode(const QByteArray &ba)
void toUnicode(QString *target, const char *chars, int len)

详细说明

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

解码器将该格式的文本转换为 Unicode,并记住调用之间所需的任何状态。

另请参阅 QTextCodec::makeDecoder() 和QTextEncoder

成员函数文档

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

为给定的codec 构建文本解码器。

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

为给定的codec 和转换flags 构建文本解码器。

[noexcept] QTextDecoder::~QTextDecoder()

摧毁解码器

QString QTextDecoder::toUnicode(const char *chars, int len)

chars 中的第一个len 字节转换为 Unicode,并返回结果。

如果没有使用所有字符(例如,如果多字节编码中只有一部分在字符末尾),解码器会记住足够的状态,以便继续下一次调用此函数。

QString QTextDecoder::toUnicode(const QByteArray &ba)

这是一个重载函数。

ba 指定的字节数组中的字节转换为 Unicode,并返回结果。

void QTextDecoder::toUnicode(QString *target, const char *chars, int len)

这是一个重载函数。

转换后的字符串以target 返回。

© 2025 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.