Obsolete Members for QtLiterals
QtLiterals 类的以下成员已被废弃。提供这些成员是为了确保旧的源代码能够继续运行。我们强烈建议不要在新代码中使用它们。
函数
(since 6.2, deprecated in 6.8) QByteArray | operator""_qba(const char *str, size_t size) |
(since 6.2, deprecated in 6.8) QString | operator""_qs(const char16_t *str, size_t size) |
函数文档
[noexcept, since 6.2, deprecated in 6.8] QByteArray operator""_qba(const char *str, size_t size)
自 6.8 版起,该函数已弃用。我们强烈建议不要在新代码中使用它。
请改用 Qt::StringLiterals 命名空间中的 `_ba `。
该字面量运算符会根据字符串字面量str 的前size 个字符,生成一个QByteArray 。
QByteArray 在编译时创建,生成的字符串数据存储在编译后对象文件的只读段中。重复的字符串字面量可能共享相同的只读内存。此功能与QByteArrayLiteral 互换,但在代码中存在大量字符串字面量时可节省输入工作量。
以下代码创建了一个QByteArray :
auto str = "hello"_qba;该函数在 Qt 6.2 中引入。
另请参阅 QByteArrayLiteral 和QtLiterals::operator""_qs(const char16_t *str, size_t size)。
[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.