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)

成员函数文档

[noexcept, deprecated in 6.4] qsizetype QByteArray::count() const

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

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

这是一个重载函数。

size() 相同。

相关非成员

[deprecated in 6.9] int qsnprintf(char *str, size_t n, const char *fmt, ...)

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

请使用 C++11 的std::snprintf() from<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 XML::StringLiterals 命名空间中的_ba

字面运算符,用于从字符串字面str 中的第一个size 字符创建QByteArray

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

以下代码创建了一个QByteArray

auto str = "hello"_qba;

该函数在 Qt 6.2 中引入。

另请参阅 QByteArrayLiteralQtLiterals::operator""_qs(const char16_t *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.