Unicode 是世界幾乎所有語言談及的文本編碼標準。現今,它被用作文本的本機編碼,在大多數現代操作係統。主要例外,微軟 Windows 應用程序仍然擁有代碼頁和 Unicode 雙重係統支持。
這些類是相關的,當操控字符串數據時。渲染文本的有關信息,見 富文本處理 概述;若字符串數據采用 XML (可擴展標記語言) 方式,見 XML 處理 概述。
| QByteArray | 字節數組 |
| QByteArrayList | 字節數組列錶 |
| QByteArrayMatcher | 保持在字節數組中可以快速匹配的字節序列 |
| QChar | 16 位 Unicode 字符 |
| QCollator | 根據本地整理算法比較字符串 |
| QCollatorSortKey | 可以用於加速字符串整理 |
| QLatin1Char | 8 位 ASCII/Latin-1 字符 |
| QLatin1String | 圍繞 US-ASCII/Latin-1 編碼字符串文字的瘦包裹器 |
| QLocale | 在數字及其各種語言的字符串錶示之間轉換 |
| QStaticByteArrayMatcher | QByteArrayMatcher 的編譯時版本 |
| QString | Unicode 字符串 |
| QStringList | 字符串列錶 |
| QStringMatcher | 保持可以在 Unicode 字符串中快速匹配的字符序列 |
| QStringRef | 圍繞 QString 子字符串的瘦包裹器 |
| QStringView | 帶有 QString API 隻讀子集的 UTF-16 字符串統一視圖 |
| QTextBoundaryFinder | 在字符串中查找 Unicode 文本邊界的辦法 |
| QTextStream | 用於讀寫文本的方便接口 |
The Unicode 聯盟 有很多可用文檔,包括
在 Qt 中,在使用 Qt 的大多數應用程序中,用戶可見的大多數 (或所有) 字符串都是使用 Unicode 存儲的。Qt 提供:
為完全利用 Unicode 的好處,推薦使用 QString 為存儲所有用戶可見字符串,而履行所有文本文件 I/O 使用 QTextStream .
Qt 中的所有函數自變量可以是用戶可見字符串,
QLabel::setText
() 及很多其它,接受
const QString &
。
QString
提供隱式鑄造從
const char *
所以事情像
label->setText("Password:");
會工作。還有函數 QObject::tr (),提供翻譯支持,像這樣:
label->setText(tr("Password:"));
QObject::tr
() 映射從
const char *
到 Unicode 字符串,和使用可安裝
QTranslator
對象來做映射。
Qt 提供瞭很多內置 QTextCodec classes, that is, classes that know how to translate between Unicode and legacy encodings to support programs that must talk to other programs or read/write files in legacy file formats.
轉換到/來自
const char *
uses a UTF-8. However, applications can easily find codecs for other locales, and set any open file or network connection to use a special codec.
Since US-ASCII and ISO-8859-1 are so common, there are also especially fast functions for mapping to and from them. For example, to open an application's icon one might do this:
QFile file(QString::fromLatin1("appicon.png"));
or
QFile file(QLatin1String("appicon.png"));
Qt supports rendering text in most languages written in the world. The detailed list of supported writing systems depends a bit on operating system support and font availability on the target system.
另請參閱 Qt 國際化 .