QByteArray Class
The QByteArray class provides an array of bytes. More…
| Header | #include <QByteArray> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| enum | Base64Option |
| enum | Base64DecodingStatus |
| typedef | Base64Options |
| typedef | iterator |
| typedef | const_iterator |
| typedef | reverse_iterator |
| typedef | const_reverse_iterator |
Public Functions
| QByteArray() | |
| QByteArray(const char *data, qsizetype size = -1) | |
| QByteArray(QByteArrayView v) | |
| QByteArray(qsizetype size, char ch) | |
| QByteArray(qsizetype size, Qt::Initialization) | |
| QByteArray(const std::string &s) | |
| QByteArray(std::string &&s) | |
| qsizetype | size() const |
| qsizetype | length() const |
| qsizetype | count() const |
| qsizetype | capacity() const |
| bool | isEmpty() const |
| bool | isNull() const |
| void | clear() |
| void | reserve(qsizetype n) |
| void | squeeze() |
| void | resize(qsizetype n) |
| void | resize(qsizetype n, char c) |
| void | resizeForOverwrite(qsizetype size) |
| QByteArray & | fill(char c, qsizetype n = -1) |
| char * | data() |
| const char * | data() const |
| const char * | constData() const |
| char | at(qsizetype i) const |
| char & | operator[](qsizetype i) |
| char | operator[](qsizetype i) const |
| char | front() const |
| char | back() const |
| char * | begin() |
| char * | end() |
| const char * | begin() const |
| const char * | end() const |
| const char * | cbegin() const |
| const char * | cend() const |
| const_iterator | constBegin() const |
| const_iterator | constEnd() const |
| reverse_iterator | rbegin() |
| const_reverse_iterator | rbegin() const |
| reverse_iterator | rend() |
| const_reverse_iterator | rend() const |
| const_reverse_iterator | crbegin() const |
| const_reverse_iterator | crend() const |
| iterator | erase(const_iterator first, const_iterator last) |
| iterator | erase(const_iterator it) |
| QByteArray & | removeAt(qsizetype pos) |
| QByteArray & | removeFirst() |
| QByteArray & | removeLast() |
| QByteArray & | removeIf(Predicate pred) |
| QByteArray & | assign(qsizetype n, char c) |
| QByteArray & | assign(InputIterator first, InputIterator last) |
| QByteArray & | setRawData(const char *data, qsizetype size) |
| void | push_front(char c) |
| void | push_front(const QByteArray &a) |
| void | shrink_to_fit() |
| void | detach() |
| bool | isDetached() const |
| qsizetype | max_size() const |
| QByteArray & | append(const QByteArray &a) |
| QByteArray & | append(const char *s) |
| QByteArray & | append(const char *s, qsizetype n) |
| QByteArray & | append(qsizetype n, char c) |
| QByteArray & | append(char c) |
| void | push_back(char c) |
| void | push_back(const QByteArray &a) |
| QByteArray & | prepend(const QByteArray &a) |
| QByteArray & | prepend(const char *s) |
| QByteArray & | prepend(char c) |
| QByteArray & | prepend(qsizetype count, char c) |
| QByteArray & | insert(qsizetype pos, const QByteArray &a) |
| QByteArray & | insert(qsizetype pos, const char *s) |
| QByteArray & | insert(qsizetype pos, char c) |
| QByteArray & | insert(qsizetype pos, qsizetype count, char c) |
| QByteArray & | remove(qsizetype pos, qsizetype len) |
| QByteArray & | replace(qsizetype pos, qsizetype len, const QByteArray &after) |
| QByteArray & | replace(const QByteArray &before, const QByteArray &after) |
| QByteArray & | replace(char before, const QByteArray &after) |
| QByteArray & | replace(char before, char after) |
| void | chop(qsizetype n) |
| void | truncate(qsizetype pos) |
| QByteArray & | operator+=(const QByteArray &a) |
| QByteArray & | operator+=(const char *s) |
| QByteArray & | operator+=(char c) |
| QByteArray | mid(qsizetype pos, qsizetype len = -1) const |
| QByteArray | left(qsizetype n) const |
| QByteArray | right(qsizetype n) const |
| QByteArray | first(qsizetype n) const |
| QByteArray | last(qsizetype n) const |
| QByteArray | sliced(qsizetype pos, qsizetype n) const |
| QByteArray | sliced(qsizetype pos) const |
| QByteArray | chopped(qsizetype n) const |
| QByteArray & | slice(qsizetype pos) |
| QByteArray & | slice(qsizetype pos, qsizetype n) |
| QByteArray & | nullTerminate() |
| QByteArray | nullTerminated() const |
| bool | isUpper() const |
| bool | isLower() const |
| bool | isValidUtf8() const |
| QByteArray | trimmed() const |
| QByteArray | simplified() const |
| QByteArray | toUpper() const |
| QByteArray | toLower() const |
| QByteArray | repeated(qsizetype times) const |
| QByteArray | leftJustified(qsizetype width, char fill = ' ', bool truncate = false) const |
| QByteArray | rightJustified(qsizetype width, char fill = ' ', bool truncate = false) const |
| bool | startsWith(const QByteArray &a) const |
| bool | startsWith(char c) const |
| bool | startsWith(const char *s) const |
| bool | endsWith(const QByteArray &a) const |
| bool | endsWith(char c) const |
| bool | endsWith(const char *s) const |
| qsizetype | indexOf(const QByteArray &a, qsizetype from = 0) const |
| qsizetype | indexOf(char c, qsizetype from = 0) const |
| qsizetype | indexOf(const char *s, qsizetype from = 0) const |
| qsizetype | lastIndexOf(const QByteArray &a, qsizetype from = -1) const |
| qsizetype | lastIndexOf(char c, qsizetype from = -1) const |
| bool | contains(const QByteArray &a) const |
| bool | contains(char c) const |
| bool | contains(const char *s) const |
| qsizetype | count(const QByteArray &a) const |
| qsizetype | count(char c) const |
| QList<QByteArray> | split(char sep) const |
| QByteArray | toHex(char separator = '\0') const |
| QByteArray | toBase64(Base64Options options = Base64Encoding) const |
| QByteArray | toPercentEncoding(const QByteArray &exclude = QByteArray(), const QByteArray &include = QByteArray(), char percent = '%') const |
| QByteArray | percentDecoded(char percent = '%') const |
| QByteArray & | setNum(qlonglong n, int base = 10) |
| QByteArray & | setNum(qulonglong n, int base = 10) |
| QByteArray & | setNum(int n, int base = 10) |
| QByteArray & | setNum(uint n, int base = 10) |
| QByteArray & | setNum(double n, char format = 'g', int precision = 6) |
| int | toInt(bool *ok = nullptr, int base = 10) const |
| uint | toUInt(bool *ok = nullptr, int base = 10) const |
| long | toLong(bool *ok = nullptr, int base = 10) const |
| ulong | toULong(bool *ok = nullptr, int base = 10) const |
| qlonglong | toLongLong(bool *ok = nullptr, int base = 10) const |
| qulonglong | toULongLong(bool *ok = nullptr, int base = 10) const |
| short | toShort(bool *ok = nullptr, int base = 10) const |
| ushort | toUShort(bool *ok = nullptr, int base = 10) const |
| double | toDouble(bool *ok = nullptr) const |
| float | toFloat(bool *ok = nullptr) const |
| std::string | toStdString() const |
| const std::string & | stdString() const |
| void | swap(QByteArray &o) |
| int | compare(const QByteArray &o, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| operator bool() const |
Static Public Members
| qsizetype | maxSize() |
| QByteArray | fromHex(const QByteArray &hex) |
| QByteArray | fromBase64(const QByteArray &base64, Base64Options options = Base64Encoding) |
| QByteArray | fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%') |
| FromBase64Result | fromBase64Encoding(const QByteArray &base64, Base64Options options = Base64Encoding) |
| QByteArray | number(qlonglong n, int base = 10) |
| QByteArray | number(qulonglong n, int base = 10) |
| QByteArray | number(int n, int base = 10) |
| QByteArray | number(uint n, int base = 10) |
| QByteArray | number(long n, int base = 10) |
| QByteArray | number(ulong n, int base = 10) |
| QByteArray | number(double n, char format = 'g', int precision = 6) |
| QByteArray | fromStdString(const std::string &s) |
| QByteArray | fromRawData(const char *data, qsizetype size) |
Detailed Description
QByteArray stores raw bytes, or 8-bit text, in a contiguous buffer. It is used wherever binary data is needed, such as I/O buffers, hashes and encoded text.
QByteArray ba("Hello");
ba.append(", world");
ba.replace("world", "Nt");
// ba == "Hello, Nt"
A QByteArray can be null or empty. A null array is one that was default constructed, constructed from a null const char *, or cleared; a null array is also empty.
See also QList.
Differences from Qt
The bytes are stored in a std::string and the array is not implicitly shared, so copies are deep and fromRawData() copies the data. There is no QString conversion. split() takes a single char separator and always keeps empty parts. Unless AbortOnBase64DecodingErrors is given, fromBase64() and fromBase64Encoding() accept both the standard and the URL-safe alphabets and skip other characters; a strict decode accepts missing = padding. The conversions toStdString() and stdString() are Nt additions. Indexes are qsizetype but are not range-checked.
Member Type Documentation
enum QByteArray::Base64DecodingStatus
The result of fromBase64Encoding().
| Constant | Description |
|---|---|
QByteArray::Ok | The data was decoded. |
QByteArray::IllegalInputLength | The number of Base64 characters cannot encode whole bytes. |
QByteArray::IllegalCharacter | The data contains a character that is not part of the alphabet. |
QByteArray::IllegalPadding | The = padding is in the wrong place or has the wrong length. |
This function was introduced in 5.15.
enum QByteArray::Base64Option
These options change how toBase64() encodes data and how fromBase64() decodes it.
| Constant | Description |
|---|---|
QByteArray::Base64Encoding | Use the standard Base64 alphabet, with + and / as the last two characters. |
QByteArray::Base64UrlEncoding | Use the URL-safe Base64 alphabet, with - and _ as the last two characters. |
QByteArray::KeepTrailingEquals | Keep the = padding at the end of the encoded data. |
QByteArray::OmitTrailingEquals | Omit the = padding at the end of the encoded data. |
QByteArray::IgnoreBase64DecodingErrors | Skip characters that are not part of the alphabet while decoding. This is the default. |
QByteArray::AbortOnBase64DecodingErrors | Stop at the first error while decoding; fromBase64Encoding() then reports it. |
typedef QByteArray::Base64Options
The Base64Options type is a typedef for QFlags<Base64Option>. It stores an OR combination of Base64Option values.
typedef QByteArray::const_iterator
A read-only random-access iterator over the bytes of the array. It is a plain const char *.
typedef QByteArray::const_reverse_iterator
The const reverse iterator type, for STL compatibility.
typedef QByteArray::iterator
A mutable random-access iterator over the bytes of the array. It is a plain char *.
typedef QByteArray::reverse_iterator
The reverse iterator type, for STL compatibility.
Member Function Documentation
QByteArray::QByteArray()
Constructs a null byte array.
See also isNull().
QByteArray::QByteArray(const char *data, qsizetype size = -1)
Constructs a byte array holding a copy of the first size bytes of data. If size is negative, data is treated as a '\0'-terminated string and its length is used. If data is nullptr, a null byte array is constructed.
QByteArray::QByteArray(QByteArrayView v)
This is an overloaded function.
Constructs a byte array with a copy of the bytes that the view v refers to. It is null if v is null. As the view converts from a QLatin1StringView, a std::string and other containers of char, this is also how a byte array is made of those.
This function was introduced in 6.8.
QByteArray::QByteArray(qsizetype size, char ch)
Constructs a byte array of size bytes, each set to ch. A negative size is treated as 0.
QByteArray::QByteArray(qsizetype size, Qt::Initialization)
This is an overloaded function.
Constructs a byte array of size bytes that the caller is about to assign. Pass Qt::Uninitialized as the second argument; Nt sets the bytes to '\0'.
QByteArray::QByteArray(const std::string &s)
Constructs a byte array holding a copy of the string s.
QByteArray::QByteArray(std::string &&s)
This is an overloaded function.
Constructs a byte array by moving the contents of the string s.
QByteArray & QByteArray::append(const QByteArray &a)
Appends the byte array a to this byte array and returns a reference to this byte array.
See also prepend() and insert().
QByteArray & QByteArray::append(const char *s)
This is an overloaded function.
Appends the '\0'-terminated string s to this byte array. If s is nullptr nothing is appended.
QByteArray & QByteArray::append(const char *s, qsizetype n)
This is an overloaded function.
Appends the first n bytes of s to this byte array.
QByteArray & QByteArray::append(qsizetype n, char c)
This is an overloaded function.
Appends n copies of the byte c to this byte array.
QByteArray & QByteArray::append(char c)
This is an overloaded function.
Appends the byte c to this byte array.
QByteArray & QByteArray::assign(qsizetype n, char c)
Replaces the contents with n copies of c and returns a reference to this array.
This function was introduced in 6.6.
template <typename InputIterator, typename = typename std::iterator_traits<InputIterator>::iterator_category>QByteArray & QByteArray::assign(InputIterator first, InputIterator last)
This is an overloaded function.
Replaces the contents with the bytes in the range [first, last) and returns a reference to this array.
This function was introduced in 6.6.
char QByteArray::at(qsizetype i) const
Returns the byte at index position i. i must be a valid index.
char QByteArray::back() const
Returns the last byte in the array. The array must not be empty.
char * QByteArray::begin()
Returns an iterator (a char *) pointing to the first byte in the array.
const char * QByteArray::begin() const
This is an overloaded function.
Returns a const iterator pointing to the first byte in the array.
qsizetype QByteArray::capacity() const
Returns the maximum number of bytes that can be stored in the array without forcing a reallocation.
See also reserve() and squeeze().
const char * QByteArray::cbegin() const
Returns a const iterator pointing to the first byte in the array.
const char * QByteArray::cend() const
Returns a const iterator pointing just after the last byte in the array.
void QByteArray::chop(qsizetype n)
Removes n bytes from the end of the array. If n is greater than or equal to size(), the result is an empty byte array.
See also truncate(), resize() and chopped().
QByteArray QByteArray::chopped(qsizetype n) const
Returns a byte array containing this byte array without its last n bytes.
void QByteArray::clear()
Clears the contents of the byte array and makes it null.
See also resize() and isNull().
int QByteArray::compare(const QByteArray &o, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Compares this byte array with o, using the case sensitivity cs, and returns a negative value, 0 or a positive value if this array sorts before, equal to or after o. For Qt::CaseInsensitive, only ASCII letters are folded.
const_iterator QByteArray::constBegin() const
Returns a const iterator pointing to the first byte in the array.
See also constEnd() and begin().
const char * QByteArray::constData() const
Returns a pointer to the const data stored in the byte array. The data is terminated with a '\0'.
See also data().
const_iterator QByteArray::constEnd() const
Returns a const iterator pointing just after the last byte in the array.
See also constBegin() and end().
bool QByteArray::contains(const QByteArray &a) const
Returns true if this byte array contains an occurrence of the byte array a; otherwise returns false.
See also indexOf() and count().
bool QByteArray::contains(char c) const
This is an overloaded function.
Returns true if this byte array contains the byte c.
bool QByteArray::contains(const char *s) const
This is an overloaded function.
Returns true if this byte array contains the '\0'-terminated string s.
qsizetype QByteArray::count() const
This is an overloaded function.
Same as size().
qsizetype QByteArray::count(const QByteArray &a) const
Returns the number of (potentially overlapping) occurrences of the byte array a in this byte array. Returns 0 if a is empty.
See also contains() and indexOf().
qsizetype QByteArray::count(char c) const
This is an overloaded function.
Returns the number of occurrences of the byte c in this byte array.
const_reverse_iterator QByteArray::crbegin() const
Returns a const reverse iterator pointing to the last byte in the array.
See also rbegin() and crend().
const_reverse_iterator QByteArray::crend() const
Returns a const reverse iterator pointing just before the first byte in the array.
See also rend() and crbegin().
char * QByteArray::data()
Returns a pointer to the data stored in the byte array. The pointer can be used to modify the bytes and stays valid until the array is resized or destroyed. The data is terminated with a '\0'.
See also constData().
const char * QByteArray::data() const
This is an overloaded function.
Returns a pointer to the const data stored in the byte array.
void QByteArray::detach()
Does nothing: a byte array in Nt never shares its data with another one. Provided so that code written for Qt compiles.
See also isDetached().
char * QByteArray::end()
Returns an iterator (a char *) pointing just after the last byte in the array.
const char * QByteArray::end() const
This is an overloaded function.
Returns a const iterator pointing just after the last byte in the array.
bool QByteArray::endsWith(const QByteArray &a) const
Returns true if this byte array ends with the byte array a; otherwise returns false.
See also startsWith() and right().
bool QByteArray::endsWith(char c) const
This is an overloaded function.
Returns true if this byte array ends with the byte c.
bool QByteArray::endsWith(const char *s) const
This is an overloaded function.
Returns true if this byte array ends with the '\0'-terminated string s.
iterator QByteArray::erase(const_iterator first, const_iterator last)
Removes the bytes from first up to, but not including, last. Returns an iterator to the byte that followed the last removed one.
This function was introduced in 6.1.
See also remove().
iterator QByteArray::erase(const_iterator it)
This is an overloaded function.
Removes the byte that it points to and returns an iterator to the byte after it.
This function was introduced in 6.5.
QByteArray & QByteArray::fill(char c, qsizetype n = -1)
Sets every byte in the array to c and returns a reference to this byte array. If n is not negative, the array is first resized to n bytes. The array is no longer null afterwards.
See also resize().
QByteArray QByteArray::first(qsizetype n) const
Returns a byte array containing the first n bytes of this byte array. Same as left().
QByteArray QByteArray::fromBase64(const QByteArray &base64, Base64Options options = Base64Encoding)
Returns the decoded copy of the Base64 array base64. Both the standard and the URL-safe alphabets are accepted, and bytes outside the alphabet, including '=' padding, are skipped. The options argument is accepted for compatibility with Qt but has no effect.
See also toBase64().
FromBase64Result QByteArray::fromBase64Encoding(const QByteArray &base64, Base64Options options = Base64Encoding)
Decodes base64 with the alphabet and error handling selected by options, and returns the bytes with the status of the decoding.
By default characters outside the alphabet are skipped, as in fromBase64(). With AbortOnBase64DecodingErrors, only the alphabet chosen by Base64Encoding or Base64UrlEncoding is accepted, = may only pad the end, and the status tells what was wrong; the decoded bytes are then empty.
This function was introduced in 5.15.
See also fromBase64() and toBase64().
QByteArray QByteArray::fromHex(const QByteArray &hex)
Returns a decoded copy of the hex encoded array hex. Bytes that are not hexadecimal digits are skipped, and a trailing odd digit is ignored.
See also toHex().
QByteArray QByteArray::fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%')
Returns a decoded copy of the percent-encoded array pctEncoded. Each percent byte followed by two hex digits is replaced by the byte they encode; anything else is copied unchanged.
See also toPercentEncoding().
QByteArray QByteArray::fromRawData(const char *data, qsizetype size)
Constructs a byte array from the first size bytes of data.
Unlike in Qt, the data is copied, not shared; this is equivalent to calling the QByteArray(const char *, qsizetype) constructor.
QByteArray QByteArray::fromStdString(const std::string &s)
Returns a byte array holding a copy of the string s.
See also toStdString().
char QByteArray::front() const
Returns the first byte in the array. The array must not be empty.
qsizetype QByteArray::indexOf(const QByteArray &a, qsizetype from = 0) const
Returns the index position of the first occurrence of the byte array a in this byte array, searching forward from index position from. A negative from counts from the end. Returns -1 if a is not found.
See also lastIndexOf(), contains() and count().
qsizetype QByteArray::indexOf(char c, qsizetype from = 0) const
This is an overloaded function.
Returns the index position of the first occurrence of the byte c in this byte array, searching forward from index position from. Returns -1 if c is not found.
qsizetype QByteArray::indexOf(const char *s, qsizetype from = 0) const
This is an overloaded function.
Returns the index position of the first occurrence of the '\0'-terminated string s, searching forward from index position from.
QByteArray & QByteArray::insert(qsizetype pos, const QByteArray &a)
Inserts the byte array a at index position pos and returns a reference to this byte array. pos must not be greater than size().
See also append(), prepend() and remove().
QByteArray & QByteArray::insert(qsizetype pos, const char *s)
This is an overloaded function.
Inserts the '\0'-terminated string s at index position pos.
QByteArray & QByteArray::insert(qsizetype pos, char c)
This is an overloaded function.
Inserts the byte c at index position pos.
QByteArray & QByteArray::insert(qsizetype pos, qsizetype count, char c)
This is an overloaded function.
Inserts count copies of the byte c at index position pos and returns a reference to this byte array.
bool QByteArray::isDetached() const
Returns true, as a byte array in Nt never shares its data.
See also detach().
bool QByteArray::isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
bool QByteArray::isLower() const
Returns true if the byte array contains no uppercase ASCII letters, that is, if it equals its toLower().
This function was introduced in 5.12.
See also isUpper() and toLower().
bool QByteArray::isNull() const
Returns true if this byte array is null; otherwise returns false.
An array is null if it was default constructed, constructed from a null const char *, or cleared, and nothing has been added to it since.
See also isEmpty() and clear().
bool QByteArray::isUpper() const
Returns true if the byte array contains no lowercase ASCII letters, that is, if it equals its toUpper().
This function was introduced in 5.12.
See also isLower() and toUpper().
bool QByteArray::isValidUtf8() const
Returns true if the byte array holds well-formed UTF-8; otherwise returns false. An empty array is valid.
This function was introduced in 6.3.
See also QString::fromUtf8() and QByteArrayView::isValidUtf8().
QByteArray QByteArray::last(qsizetype n) const
Returns a byte array containing the last n bytes of this byte array. Same as right().
See also first() and sliced().
qsizetype QByteArray::lastIndexOf(const QByteArray &a, qsizetype from = -1) const
Returns the index position of the last occurrence of the byte array a in this byte array, searching backward from index position from. A negative from counts from the end, so the default of -1 starts at the last byte. Returns -1 if a is not found.
See also indexOf() and contains().
qsizetype QByteArray::lastIndexOf(char c, qsizetype from = -1) const
This is an overloaded function.
Returns the index position of the last occurrence of the byte c in this byte array, searching backward from index position from. Returns -1 if c is not found.
QByteArray QByteArray::left(qsizetype n) const
Returns a byte array containing the first n bytes of this byte array. If n is not less than size(), the whole array is returned.
See also right(), first() and mid().
QByteArray QByteArray::leftJustified(qsizetype width, char fill = ' ', bool truncate = false) const
Returns a byte array of size width containing this byte array padded on the right with the byte fill. If this byte array is longer than width and truncate is true, the result is truncated to width bytes; otherwise it is returned unchanged.
See also rightJustified().
qsizetype QByteArray::length() const
Same as size().
qsizetype QByteArray::max_size() const
Returns the largest number of bytes an array can theoretically hold.
This function was introduced in 6.8.
See also maxSize().
qsizetype QByteArray::maxSize()
Returns the largest number of bytes an array can theoretically hold.
This function was introduced in 6.8.
See also max_size().
QByteArray QByteArray::mid(qsizetype pos, qsizetype len = -1) const
Returns a byte array containing len bytes from this byte array, starting at index position pos. If len is negative, or if pos + len is beyond the end of the array, all bytes from pos to the end are returned. If pos is negative, it is treated as 0 and len is reduced accordingly. If pos is beyond the end of the array, an empty, non-null byte array is returned.
See also left(), right() and sliced().
QByteArray & QByteArray::nullTerminate()
Makes sure that the data is followed by a '\0' byte and returns a reference to this byte array. Nt keeps the data null-terminated already, so this only clears the null state of a null array.
This function was introduced in 6.5.
See also nullTerminated() and constData().
QByteArray QByteArray::nullTerminated() const
Returns a copy of this byte array whose data is followed by a '\0' byte.
This function was introduced in 6.5.
See also nullTerminate().
QByteArray QByteArray::number(qlonglong n, int base = 10)
Returns a byte array containing the string equivalent of the number n in the given base, which should be between 2 and 36. The default base is 10.
See also setNum() and toLongLong().
QByteArray QByteArray::number(qulonglong n, int base = 10)
This is an overloaded function.
Returns a byte array containing the string equivalent of the unsigned number n in the given base.
QByteArray QByteArray::number(int n, int base = 10)
This is an overloaded function.
Returns a byte array containing the string equivalent of the number n in the given base.
QByteArray QByteArray::number(uint n, int base = 10)
This is an overloaded function.
Returns a byte array containing the string equivalent of the number n in the given base.
QByteArray QByteArray::number(long n, int base = 10)
This is an overloaded function.
Returns a byte array containing the string equivalent of the number n in the given base.
QByteArray QByteArray::number(ulong n, int base = 10)
This is an overloaded function.
Returns a byte array containing the string equivalent of the number n in the given base.
QByteArray QByteArray::number(double n, char format = 'g', int precision = 6)
This is an overloaded function.
Returns a byte array containing the string equivalent of the floating-point number n. format is one of 'e', 'E', 'f', 'g' or 'G', and precision is the number of digits after the decimal point (or of significant digits for 'g' and 'G').
QByteArray::operator bool() const
Returns true if the byte array is not empty; otherwise returns false.
See also isEmpty().
QByteArray & QByteArray::operator+=(const QByteArray &a)
Appends the byte array a to this byte array and returns a reference to this byte array.
QByteArray & QByteArray::operator+=(const char *s)
This is an overloaded function.
Appends the '\0'-terminated string s to this byte array.
QByteArray & QByteArray::operator+=(char c)
This is an overloaded function.
Appends the byte c to this byte array.
char & QByteArray::operator[](qsizetype i)
Returns a reference to the byte at index position i, which can be assigned to. i must be a valid index.
See also at().
char QByteArray::operator[](qsizetype i) const
This is an overloaded function.
Same as at(i).
QByteArray QByteArray::percentDecoded(char percent = '%') const
Returns a copy of the byte array with each percent followed by two hex digits replaced by the byte they encode. Same as fromPercentEncoding(*this, percent).
This function was introduced in 6.4.
See also fromPercentEncoding().
QByteArray & QByteArray::prepend(const QByteArray &a)
Prepends the byte array a to this byte array and returns a reference to this byte array.
See also append() and insert().
QByteArray & QByteArray::prepend(const char *s)
This is an overloaded function.
Prepends the '\0'-terminated string s to this byte array.
QByteArray & QByteArray::prepend(char c)
This is an overloaded function.
Prepends the byte c to this byte array.
QByteArray & QByteArray::prepend(qsizetype count, char c)
This is an overloaded function.
Prepends count copies of the byte c and returns a reference to this byte array.
void QByteArray::push_back(char c)
Same as append(c). This function is provided for STL compatibility.
void QByteArray::push_back(const QByteArray &a)
This is an overloaded function.
Same as append(a). This function is provided for STL compatibility.
void QByteArray::push_front(char c)
Inserts c at the beginning of the array. Provided for compatibility with the standard library.
See also prepend() and push_back().
void QByteArray::push_front(const QByteArray &a)
This is an overloaded function.
Inserts a at the beginning of the array.
reverse_iterator QByteArray::rbegin()
Returns a reverse iterator pointing to the last byte in the array.
See also rend() and crbegin().
const_reverse_iterator QByteArray::rbegin() const
This is an overloaded function.
QByteArray & QByteArray::remove(qsizetype pos, qsizetype len)
Removes len bytes from the array, starting at index position pos, and returns a reference to this byte array. If pos is out of range or len is not positive, nothing happens. If pos + len is beyond the end of the array, bytes are removed up to the end.
See also insert(), replace() and chop().
QByteArray & QByteArray::removeAt(qsizetype pos)
Removes the byte at index position pos and returns a reference to this array. Nothing happens if pos is out of range.
This function was introduced in 6.5.
See also remove(), removeFirst() and removeLast().
QByteArray & QByteArray::removeFirst()
Removes the first byte and returns a reference to this array. Nothing happens if the array is empty.
This function was introduced in 6.5.
See also removeLast() and removeAt().
template <typename Predicate>QByteArray & QByteArray::removeIf(Predicate pred)
Removes every byte for which pred returns true and returns a reference to this array. pred is called with a char.
This function was introduced in 6.1.
See also remove().
QByteArray & QByteArray::removeLast()
Removes the last byte and returns a reference to this array. Nothing happens if the array is empty.
This function was introduced in 6.5.
See also removeFirst() and chop().
reverse_iterator QByteArray::rend()
Returns a reverse iterator pointing just before the first byte in the array.
See also rbegin() and crend().
const_reverse_iterator QByteArray::rend() const
This is an overloaded function.
QByteArray QByteArray::repeated(qsizetype times) const
Returns a copy of this byte array repeated times times. If times is less than 1, an empty byte array is returned.
QByteArray & QByteArray::replace(qsizetype pos, qsizetype len, const QByteArray &after)
Replaces len bytes from index position pos with the byte array after and returns a reference to this byte array. If pos is out of range, nothing happens.
See also insert() and remove().
QByteArray & QByteArray::replace(const QByteArray &before, const QByteArray &after)
This is an overloaded function.
Replaces every occurrence of the byte array before with the byte array after and returns a reference to this byte array. If before is empty, nothing happens.
QByteArray & QByteArray::replace(char before, const QByteArray &after)
This is an overloaded function.
Replaces every occurrence of the byte before with the byte array after and returns a reference to this byte array.
QByteArray & QByteArray::replace(char before, char after)
This is an overloaded function.
Replaces every occurrence of the byte before with the byte after and returns a reference to this byte array.
void QByteArray::reserve(qsizetype n)
Attempts to allocate memory for at least n bytes, so that later appends do not reallocate.
See also capacity() and squeeze().
void QByteArray::resize(qsizetype n)
Sets the size of the byte array to n bytes. If n is larger than the current size, the new bytes are set to '\0'. The array is no longer null afterwards.
See also size(), truncate() and chop().
void QByteArray::resize(qsizetype n, char c)
This is an overloaded function.
Sets the size of the byte array to n bytes. If n is larger than the current size, the new bytes are set to c.
void QByteArray::resizeForOverwrite(qsizetype size)
Sets the size of the byte array to size bytes, for a caller that is about to assign every new byte. Nt sets them to '\0'.
This function was introduced in 6.8.
See also resize().
QByteArray QByteArray::right(qsizetype n) const
Returns a byte array containing the last n bytes of this byte array. If n is not less than size(), the whole array is returned.
See also left(), last() and mid().
QByteArray QByteArray::rightJustified(qsizetype width, char fill = ' ', bool truncate = false) const
Returns a byte array of size width containing the byte fill followed by this byte array. If this byte array is longer than width and truncate is true, the result is truncated to the first width bytes; otherwise it is returned unchanged.
See also leftJustified().
QByteArray & QByteArray::setNum(qlonglong n, int base = 10)
Sets the byte array to the string equivalent of the number n in the given base, and returns a reference to this byte array.
See also number() and toLongLong().
QByteArray & QByteArray::setNum(qulonglong n, int base = 10)
This is an overloaded function.
Sets the byte array to the string equivalent of the number n in the given base.
QByteArray & QByteArray::setNum(int n, int base = 10)
This is an overloaded function.
Sets the byte array to the string equivalent of the number n in the given base.
QByteArray & QByteArray::setNum(uint n, int base = 10)
This is an overloaded function.
Sets the byte array to the string equivalent of the number n in the given base.
QByteArray & QByteArray::setNum(double n, char format = 'g', int precision = 6)
This is an overloaded function.
Sets the byte array to the string equivalent of the floating-point number n, formatted with the given format and precision as described for number().
QByteArray & QByteArray::setRawData(const char *data, qsizetype size)
Replaces the contents with a copy of the size bytes at data and returns a reference to this array. Unlike in Qt, the data is copied.
See also fromRawData().
void QByteArray::shrink_to_fit()
Releases memory that is not needed to hold the bytes. Provided for compatibility with the standard library.
See also squeeze().
QByteArray QByteArray::simplified() const
Returns a byte array with whitespace removed from the start and the end, and with each sequence of internal whitespace replaced with a single space. Whitespace means the ASCII characters space, '\t', '\n', '\v', '\f' and '\r'.
See also trimmed().
qsizetype QByteArray::size() const
Returns the number of bytes in the array.
See also isEmpty() and resize().
QByteArray & QByteArray::slice(qsizetype pos)
Removes the bytes before index position pos and returns a reference to this byte array. pos must not be greater than size().
This function was introduced in 6.8.
See also sliced() and truncate().
QByteArray & QByteArray::slice(qsizetype pos, qsizetype n)
This is an overloaded function.
Keeps the n bytes starting at index position pos and returns a reference to this byte array. The range must lie within the array.
This function was introduced in 6.8.
QByteArray QByteArray::sliced(qsizetype pos, qsizetype n) const
Returns a byte array containing n bytes of this byte array, starting at index position pos. Same as mid(pos, n).
See also first(), last() and chopped().
QByteArray QByteArray::sliced(qsizetype pos) const
This is an overloaded function.
Returns a byte array containing the bytes of this byte array from index position pos to the end.
QList<QByteArray> QByteArray::split(char sep) const
Splits the byte array into subarrays wherever the byte sep occurs and returns the list of those arrays. Empty parts are kept, so an array without sep yields a list containing a copy of the whole array.
See also indexOf().
void QByteArray::squeeze()
Releases any memory not required to store the array's data.
See also reserve() and capacity().
bool QByteArray::startsWith(const QByteArray &a) const
Returns true if this byte array starts with the byte array a; otherwise returns false.
See also endsWith() and left().
bool QByteArray::startsWith(char c) const
This is an overloaded function.
Returns true if this byte array starts with the byte c.
bool QByteArray::startsWith(const char *s) const
This is an overloaded function.
Returns true if this byte array starts with the '\0'-terminated string s.
const std::string & QByteArray::stdString() const
Returns a const reference to the std::string that stores the data, without copying it. The reference is invalidated when the byte array is modified or destroyed.
See also toStdString().
void QByteArray::swap(QByteArray &o)
Swaps this byte array with o. This operation is very fast and never fails.
QByteArray QByteArray::toBase64(Base64Options options = Base64Encoding) const
Returns a copy of the byte array encoded as Base64, using the alphabet and padding selected by options.
See also fromBase64() and Base64Option.
double QByteArray::toDouble(bool *ok = nullptr) const
Returns the byte array converted to a double. If ok is not nullptr, it is set to true if the conversion succeeded and to false otherwise. Returns 0.0 on failure.
See also number() and toFloat().
float QByteArray::toFloat(bool *ok = nullptr) const
Returns the byte array converted to a float. If ok is not nullptr, it is set to true if the conversion succeeded and to false otherwise. Returns 0.0 on failure.
See also toDouble() and number().
QByteArray QByteArray::toHex(char separator = '\0') const
Returns a hex encoded copy of the byte array, using lowercase digits. If separator is not '\0', it is inserted between the hex digits of consecutive bytes.
See also fromHex().
int QByteArray::toInt(bool *ok = nullptr, int base = 10) const
Returns the byte array converted to an int using the given base. If ok is not nullptr, it is set to true if the conversion succeeded and the value fits in an int, and to false otherwise. Returns 0 on failure.
See also number() and toLongLong().
long QByteArray::toLong(bool *ok = nullptr, int base = 10) const
Returns the byte array converted to a long using the given base. If ok is not nullptr, it is set to true if the conversion succeeded and the value fits in a long, and to false otherwise. Returns 0 on failure.
See also number() and toLongLong().
qlonglong QByteArray::toLongLong(bool *ok = nullptr, int base = 10) const
Returns the byte array converted to a long long using the given base, which must be between 2 and 36, or 0 to detect the base from the prefix. If ok is not nullptr, it is set to true if the conversion succeeded and to false otherwise. Returns 0 on failure.
See also number(), toULongLong() and toInt().
QByteArray QByteArray::toLower() const
Returns a lowercase copy of the byte array. Only the ASCII letters A to Z are converted; all other bytes are left unchanged.
See also toUpper().
QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude = QByteArray(), const QByteArray &include = QByteArray(), char percent = '%') const
Returns a percent-encoded copy of the byte array. The unreserved characters A-Z a-z 0-9 - . _ ~ and the bytes in exclude are left as they are, unless they also occur in include. Every other byte is replaced by percent followed by two uppercase hex digits.
See also fromPercentEncoding().
short QByteArray::toShort(bool *ok = nullptr, int base = 10) const
Returns the byte array converted to a short using the given base. If ok is not nullptr, it is set to true if the conversion succeeded and the value fits in a short, and to false otherwise. Returns 0 on failure.
See also number() and toLongLong().
std::string QByteArray::toStdString() const
Returns a copy of the data as a std::string.
See also fromStdString() and stdString().
uint QByteArray::toUInt(bool *ok = nullptr, int base = 10) const
Returns the byte array converted to an unsigned int using the given base. If ok is not nullptr, it is set to true if the conversion succeeded and the value fits in an unsigned int, and to false otherwise. Returns 0 on failure.
See also number() and toULongLong().
ulong QByteArray::toULong(bool *ok = nullptr, int base = 10) const
Returns the byte array converted to an unsigned long using the given base. If ok is not nullptr, it is set to true if the conversion succeeded and the value fits in an unsigned long, and to false otherwise. Returns 0 on failure.
See also number() and toULongLong().
qulonglong QByteArray::toULongLong(bool *ok = nullptr, int base = 10) const
Returns the byte array converted to an unsigned long long using the given base. If ok is not nullptr, it is set to true if the conversion succeeded and to false otherwise. Returns 0 on failure.
See also number() and toLongLong().
QByteArray QByteArray::toUpper() const
Returns an uppercase copy of the byte array. Only the ASCII letters a to z are converted; all other bytes are left unchanged.
See also toLower().
ushort QByteArray::toUShort(bool *ok = nullptr, int base = 10) const
Returns the byte array converted to an unsigned short using the given base. If ok is not nullptr, it is set to true if the conversion succeeded and the value fits in an unsigned short, and to false otherwise. Returns 0 on failure.
See also number() and toULongLong().
QByteArray QByteArray::trimmed() const
Returns a byte array with whitespace removed from the start and the end. Whitespace means the ASCII characters space, '\t', '\n', '\v', '\f' and '\r'.
See also simplified().
void QByteArray::truncate(qsizetype pos)
Truncates the array at index position pos. If pos is beyond the end of the array, nothing happens.