Obsolete Members for QByteArray

The following members of class QByteArray are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.

Public Functions

(obsolete) operator const char *() const
(obsolete) operator const void *() const

Related Non-Members

(obsolete) int qsnprintf(char *str, size_t n, const char *fmt, ...)
(obsolete) int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)

Member Function Documentation

QByteArray::operator const char *() const

Returns a pointer to the data stored in the byte array. The pointer can be used to access the bytes that compose the array. The data is '\0'-terminated. The pointer remains valid as long as the array isn't reallocated or destroyed.

This operator is mostly useful to pass a byte array to a function that accepts a const char *.

You can disable this operator by defining QT_NO_CAST_FROM_BYTEARRAY when you compile your applications.

Note: A QByteArray can store any byte values including '\0's, but most functions that take char * arguments assume that the data ends at the first '\0' they encounter.

See also constData().

QByteArray::operator const void *() const

Returns a pointer to the data stored in the byte array. The pointer can be used to access the bytes that compose the array. The data is '\0'-terminated. The pointer remains valid as long as the array isn't reallocated or destroyed.

This operator is mostly useful to pass a byte array to a function that accepts a const char *.

You can disable this operator by defining QT_NO_CAST_FROM_BYTEARRAY when you compile your applications.

Note: A QByteArray can store any byte values including '\0's, but most functions that take char * arguments assume that the data ends at the first '\0' they encounter.

See also constData().

Related Non-Members

int qsnprintf(char *str, size_t n, const char *fmt, ...)

Use C++11's std::snprintf() from <cstdio> instead.

A portable snprintf() function, calls qvsnprintf.

fmt is the printf() format string. The result is put into str, which is a buffer of at least n bytes.

Warning: Call this function only when you know what you are doing since it shows different behavior on certain platforms. Use QString::asprintf() to format a string instead.

See also qvsnprintf() and QString::asprintf().

int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)

Use C++11's std::vsnprintf() from <cstdio> instead.

A portable vsnprintf() function. Will call ::vsnprintf(), ::_vsnprintf(), or ::vsnprintf_s depending on the system, or fall back to an internal version.

fmt is the printf() format string. The result is put into str, which is a buffer of at least n bytes.

The caller is responsible to call va_end() on ap.

Warning: Since vsnprintf() shows different behavior on certain platforms, you should not rely on the return value or on the fact that you will always get a 0 terminated string back.

Ideally, you should never call this function but use QString::asprintf() instead.

See also qsnprintf() and QString::asprintf().