- Qt 5.15
- Qt Core
- C++ Classes
- QByteArray
- Qt 5.15.15 Reference Documentation

# 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)` QByteArray & | append(const QString &str)
`(obsolete)` int | indexOf(const QString &str, int from = 0) const
`(obsolete)` QByteArray & | insert(int i, const QString &str)
`(obsolete)` int | lastIndexOf(const QString &str, int from = -1) const
`(obsolete)` QByteArray & | replace(const QString &before, const char *after)
`(obsolete)` QByteArray & | replace(char before, const QString &after)
`(obsolete)` QByteArray & | replace(const QString &before, const QByteArray &after)
`(obsolete)` QByteArray & | operator+=(const QString &str)

## Member Function Documentation

### const char *QByteArray::operator const char *() const

### const void *QByteArray::operator const void *() const

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Use constData() instead.

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 &QByteArray::append(const QString &str)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Appends the string str to this byte array. The Unicode data is converted into 8-bit characters using QString::toUtf8().

You can disable this function by defining `QT_NO_CAST_TO_ASCII` when you compile your applications. You then need to call QString::toUtf8() (or QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to convert the data to `const char *`.

### int QByteArray::indexOf(const QString &str, int from = 0) const

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Returns the index position of the first occurrence of the string str in the byte array, searching forward from index position from. Returns -1 if str could not be found.

The Unicode data is converted into 8-bit characters using QString::toUtf8().

You can disable this function by defining `QT_NO_CAST_TO_ASCII` when you compile your applications. You then need to call QString::toUtf8() (or QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to convert the data to `const char *`.

### QByteArray &QByteArray::insert(int i, const QString &str)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Inserts the string str at index position i in the byte array. The Unicode data is converted into 8-bit characters using QString::toUtf8().

If i is greater than size(), the array is first extended using resize().

You can disable this function by defining `QT_NO_CAST_TO_ASCII` when you compile your applications. You then need to call QString::toUtf8() (or QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to convert the data to `const char *`.

### int QByteArray::lastIndexOf(const QString &str, int from = -1) const

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Returns the index position of the last occurrence of the string str in the byte array, searching backward from index position from. If from is -1 (the default), the search starts at the last (size() - 1) byte. Returns -1 if str could not be found.

The Unicode data is converted into 8-bit characters using QString::toUtf8().

You can disable this function by defining `QT_NO_CAST_TO_ASCII` when you compile your applications. You then need to call QString::toUtf8() (or QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to convert the data to `const char *`.

### QByteArray &QByteArray::replace(const QString &before, const char *after)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Replaces every occurrence of the string before with the string after.

### QByteArray &QByteArray::replace(char before, const QString &after)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Replaces every occurrence of the character before with the string after. The Unicode data is converted into 8-bit characters using QString::toUtf8().

You can disable this function by defining `QT_NO_CAST_TO_ASCII` when you compile your applications. You then need to call QString::toUtf8() (or QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to convert the data to `const char *`.

### QByteArray &QByteArray::replace(const QString &before, const QByteArray &after)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Replaces every occurrence of the string before with the byte array after. The Unicode data is converted into 8-bit characters using QString::toUtf8().

You can disable this function by defining `QT_NO_CAST_TO_ASCII` when you compile your applications. You then need to call QString::toUtf8() (or QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to convert the data to `const char *`.

### QByteArray &QByteArray::operator+=(const QString &str)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Appends the string str onto the end of this byte array and returns a reference to this byte array. The Unicode data is converted into 8-bit characters using QString::toUtf8().

You can disable this function by defining `QT_NO_CAST_TO_ASCII` when you compile your applications. You then need to call QString::toUtf8() (or QString::toLatin1() or QString::toLocal8Bit()) explicitly if you want to convert the data to `const char *`.