Obsolete Members for QString

QString 的以下成员已被弃用。提供这些成员是为了保持旧源代码的正常运行。我们强烈建议不要在新代码中使用它们。

公共函数

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

静态公共成员

(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)

成员函数文档

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

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

请使用size() 或length() 代替它。

此函数重载了 count()。

size() 相同。

[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 重载。

相关非成员

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

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

请使用 Qt XML::StringLiterals 命名空间中的_s

字面操作符,用于从 char16_t 字符串字面str 中的第一个size 字符创建QString

QString 在编译时创建,生成的字符串数据存储在编译对象文件的只读段中。重复的字面量可以共享同一个只读存储器。该功能可与QStringLiteral 互换使用,但当代码中有许多字符串字面量时,可节省键入次数。

以下代码创建了一个QString

auto str = u"hello"_qs;

该函数在 Qt 6.2 中引入。

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

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