Obsolete Members for QString

QString 类的以下成员已被废弃。提供这些成员是为了确保旧源代码能够继续运行。我们强烈建议不要在新代码中使用它们。

公共函数

(deprecated in 6.4) qsizetype count() const
(deprecated) QString &setUtf16(const ushort *unicode, qsizetype size)
(deprecated) const ushort *utf16() const

静态公共成员

(deprecated in 6.0) QString fromUcs4(const uint *str, qsizetype size = -1)
(deprecated in 6.0) QString fromUtf16(const ushort *str, qsizetype size = -1)

相关的非成员

(since 6.2, deprecated in 6.8) QString operator""_qs(const char16_t *str, size_t size)

成员函数文档

[constexpr, deprecated in 6.4] qsizetype QString::count() const

自 6.4 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用 `size()` 或 `length()`。

与 `size()` 功能相同。

此函数重载了 `QString::count()`。

[static, deprecated in 6.0] QString QString::fromUcs4(const uint *str, qsizetype size = -1)

该函数自 6.0 起已弃用。我们强烈建议不要在新代码中使用它。

请改用char32_t 重载版本。

[static, deprecated in 6.0] QString QString::fromUtf16(const ushort *str, qsizetype size = -1)

自 6.0 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用char16_t 重载版本。

[deprecated] QString &QString::setUtf16(const ushort *unicode, qsizetype size)

此函数已弃用。我们强烈建议不要在新的代码中使用它。

请改用char16_t 重载函数。

[deprecated] const ushort *QString::utf16() const

此函数已弃用。我们强烈建议不要在新代码中使用它。

请使用 `nullTerminate()`,并将 `data()` 强制转换为 `const char16_t *`。

返回QString ,其形式为以'\0'结尾的无符号短整型数组。该结果在字符串被修改之前始终有效。

返回的字符串采用主机字节序。

另请参阅 setUtf16() 和unicode()。

相关非成员

[noexcept, since 6.2, deprecated in 6.8] QString operator""_qs(const char16_t *str, size_t size)

自 6.8 版起,此函数已弃用。我们强烈建议不要在新代码中使用它。

请改用 Qt::StringLiterals 命名空间中的 `_s `。

该文字运算符会从 char16_t 字符串文字str 的前size 个字符中创建一个 `QString `。

QString 在编译时生成,生成的字符串数据存储在编译后对象文件的只读段中。重复的字符串常量可能共享同一块只读内存。此功能与QStringLiteral 功能等同,但在代码中存在大量字符串常量时可节省输入工作量。

以下代码创建了一个QString :

auto str = u"hello"_qs;

该函数在 Qt 6.2 中引入。

另请参阅 QStringLiteral 和QtLiterals::operator""_qba(const char *str, size_t size)。

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