Obsolete Members for QByteArray
QByteArray 类的以下成员已被废弃。提供这些成员是为了确保旧源代码能够继续运行。我们强烈建议不要在新代码中使用它们。
公共函数
(deprecated in 6.4) qsizetype | count() const |
相关的非成员
(deprecated in 6.9) int | qsnprintf(char *str, size_t n, const char *fmt, ...) |
(deprecated in 6.9) int | qvsnprintf(char *str, size_t n, const char *fmt, va_list ap) |
(since 6.2, deprecated in 6.8) QByteArray | operator""_qba(const char *str, size_t size) |
成员函数文档
[constexpr noexcept, deprecated in 6.4] qsizetype QByteArray::count() const
自 6.4 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
与size() 相同。
这是一个重载函数。
相关的非成员
[deprecated in 6.9] int qsnprintf(char *str, size_t n, const char *fmt, ...)
自 6.9 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请改用 C++11 中的 `std::snprintf() `(位于<cstdio> )。
一个可移植的 snprintf() 函数,调用 qvsnprintf。
fmt 是printf() 的格式字符串。结果将写入str ,该缓冲区大小至少为n 字节。
警告:请 仅在确知操作内容时调用 此函数,因为它在某些平台上表现不同。建议改用QString::asprintf() 来格式化字符串。
另请参阅 qvsnprintf() 和QString::asprintf()。
[deprecated in 6.9] int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
自 6.9 版本起,此函数已被弃用。我们强烈建议不要在新代码中使用它。
请改用 C++11 的 `std::vsnprintf() `(参见<cstdio> )。
一个可移植的 `vsnprintf() ` 函数。将根据系统调用 `::vsnprintf()`、`::_vsnprintf()` 或 `::vsnprintf_s `,否则将回退到内部实现。
fmt 是printf() 的格式字符串。结果将写入str ,这是一个至少有n 字节的缓冲区。
调用方负责对ap 调用va_end() 。
警告:由于 vsnprintf() 在某些平台上的行为不同,您不应依赖其返回值,也不应依赖其返回的字符串总是以 0 结尾这一事实。此外,WebAssembly 和 Android 平台上对%a (十六进制浮点数)和%ls (宽字符串)的处理方式也存在差异。
理想情况下,您不应调用此函数,而应改用QString::asprintf()。
另请参阅 qsnprintf() 和QString::asprintf()。
[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)。
© 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.