qbytearrary怎么python 处理小数数

QByteArray
QByteArray Class
class provides an array of bytes.
Header: #include &QByteArray&
Inherited By:
Note: All functions in this class are .
Public Functions
(const char * str)
(const char * data, int size)
(int size, char ch)
(const QByteArray & other)
QByteArray & (const QByteArray & ba)
QByteArray & (const QString & str)
QByteArray & (const char * str)
QByteArray & (const char * str, int len)
QByteArray & (char ch)
char (int i) const
int () const
void (int n)
const char * () const
bool (const QByteArray & ba) const
bool (const char * str) const
bool (char ch) const
int (const QByteArray & ba) const
int (const char * str) const
int (char ch) const
int () const
const char * () const
bool (const QByteArray & ba) const
bool (const char * str) const
bool (char ch) const
QByteArray & (char ch, int size = -1)
int (const QByteArray & ba, int from = 0) const
int (const QString & str, int from = 0) const
int (const char * str, int from = 0) const
int (char ch, int from = 0) const
QByteArray & (int i, const QByteArray & ba)
QByteArray & (int i, const QString & str)
QByteArray & (int i, const char * str)
QByteArray & (int i, const char * str, int len)
QByteArray & (int i, char ch)
bool () const
bool () const
int (const QByteArray & ba, int from = -1) const
int (const QString & str, int from = -1) const
int (const char * str, int from = -1) const
int (char ch, int from = -1) const
QByteArray (int len) const
QByteArray (int width, char fill = ' ', bool truncate = false) const
int () const
QByteArray (int pos, int len = -1) const
QByteArray & (const QByteArray & ba)
QByteArray & (const char * str)
QByteArray & (const char * str, int len)
QByteArray & (char ch)
void (const QByteArray & other)
void (const char * str)
void (char ch)
void (const QByteArray & other)
void (const char * str)
void (char ch)
QByteArray & (int pos, int len)
QByteArray (int times) const
QByteArray & (int pos, int len, const QByteArray & after)
QByteArray & (int pos, int len, const char * after)
QByteArray & (int pos, int len, const char * after, int alen)
QByteArray & (const QByteArray & before, const QByteArray & after)
QByteArray & (const char * before, const QByteArray & after)
QByteArray & (const char * before, int bsize, const char * after, int asize)
QByteArray & (const QByteArray & before, const char * after)
QByteArray & (const QString & before, const QByteArray & after)
QByteArray & (const QString & before, const char * after)
QByteArray & (const char * before, const char * after)
QByteArray & (char before, const QByteArray & after)
QByteArray & (char before, const QString & after)
QByteArray & (char before, const char * after)
QByteArray & (char before, char after)
void (int size)
void (int size)
QByteArray (int len) const
QByteArray (int width, char fill = ' ', bool truncate = false) const
QByteArray & (int n, int base = 10)
QByteArray & (uint n, int base = 10)
QByteArray & (short n, int base = 10)
QByteArray & (ushort n, int base = 10)
QByteArray & (qlonglong n, int base = 10)
QByteArray & (qulonglong n, int base = 10)
QByteArray & (double n, char f = 'g', int prec = 6)
QByteArray & (float n, char f = 'g', int prec = 6)
QByteArray & (const char * data, uint size)
QByteArray () const
int () const
QList&QByteArray& (char sep) const
bool (const QByteArray & ba) const
bool (const char * str) const
bool (char ch) const
void (QByteArray & other)
QByteArray () const
double (bool * ok = 0) const
float (bool * ok = 0) const
QByteArray () const
int (bool * ok = 0, int base = 10) const
long (bool * ok = 0, int base = 10) const
qlonglong (bool * ok = 0, int base = 10) const
QByteArray () const
QByteArray (const QByteArray & exclude = QByteArray(), const QByteArray & include = QByteArray(), char percent = '%') const
short (bool * ok = 0, int base = 10) const
uint (bool * ok = 0, int base = 10) const
ulong (bool * ok = 0, int base = 10) const
qulonglong (bool * ok = 0, int base = 10) const
ushort (bool * ok = 0, int base = 10) const
QByteArray () const
QByteArray () const
void (int pos)
bool (const QString & str) const
QByteArray & (const QByteArray & ba)
QByteArray & (const QString & str)
QByteArray & (const char * str)
QByteArray & (char ch)
bool (const QString & str) const
bool (const QString & str) const
QByteArray & (const QByteArray & other)
QByteArray & (QByteArray && other)
QByteArray & (const char * str)
bool (const QString & str) const
bool (const QString & str) const
bool (const QString & str) const
QByteRef (int i)
char (int i) const
QByteRef (uint i)
char (uint i) const
Static Public Members
QByteArray (const QByteArray & base64)
QByteArray (const QByteArray & hexEncoded)
QByteArray (const QByteArray & input, char percent = '%')
QByteArray (const char * data, int size)
QByteArray (int n, int base = 10)
QByteArray (uint n, int base = 10)
QByteArray (qlonglong n, int base = 10)
QByteArray (qulonglong n, int base = 10)
QByteArray (double n, char f = 'g', int prec = 6)
Related Non-Members
quint16 (const char * data, uint len)
QByteArray (const QByteArray & data, int compressionLevel = -1)
QByteArray (const uchar * data, int nbytes, int compressionLevel = -1)
QByteArray (const QByteArray & data)
QByteArray (const uchar * data, int nbytes)
int (char * str, size_t n, const char * fmt, ...)
int (const char * str1, const char * str2)
char * (char * dst, const char * src)
char * (const char * src)
int (const char * str1, const char * str2)
uint (const char * str)
int (const char * str1, const char * str2, uint len)
char * (char * dst, const char * src, uint len)
int (const char * str1, const char * str2, uint len)
uint (const char * str, uint maxlen)
int (char * str, size_t n, const char * fmt, va_list ap)
bool (const QByteArray & a1, const QByteArray & a2)
bool (const QByteArray & a1, const char * a2)
bool (const char * a1, const QByteArray & a2)
const QByteArray (const QByteArray & a1, const QByteArray & a2)
const QByteArray (const QByteArray & a1, const char * a2)
const QByteArray (const QByteArray & a1, char a2)
const QByteArray (const char * a1, const QByteArray & a2)
const QByteArray (char a1, const QByteArray & a2)
bool (const QByteArray & a1, const QByteArray & a2)
bool (const QByteArray & a1, const char * a2)
bool (const char * a1, const QByteArray & a2)
QDataStream & (QDataStream & out, const QByteArray & ba)
bool (const QByteArray & a1, const QByteArray & a2)
bool (const QByteArray & a1, const char * a2)
bool (const char * a1, const QByteArray & a2)
bool (const QByteArray & a1, const QByteArray & a2)
bool (const QByteArray & a1, const char * a2)
bool (const char * a1, const QByteArray & a2)
bool (const QByteArray & a1, const QByteArray & a2)
bool (const QByteArray & a1, const char * a2)
bool (const char * a1, const QByteArray & a2)
bool (const QByteArray & a1, const QByteArray & a2)
bool (const QByteArray & a1, const char * a2)
bool (const char * a1, const QByteArray & a2)
QDataStream & (QDataStream & in, QByteArray & ba)
Detailed Description
class provides an array of bytes.
can be used to store both raw bytes (including '\0's) and traditional 8-bit '\0'-terminated strings. Using
is much more convenient than using const char *. Behind the scenes, it always ensures that the data is followed by a '\0' terminator, and uses
(copy-on-write) to reduce memory usage and avoid needless copying of data.
In addition to , Qt also provides the
class to store string data. For most purposes,
is the class you want to use. It stores 16-bit Unicode characters, making it easy to store non-ASCII/non-Latin-1 characters in your application. Furthermore,
is used throughout in the Qt API. The two main cases where
is appropriate are when you need to store raw binary data, and when memory conservation is critical (e.g., with Qt for Embedded Linux).
One way to initialize a
is simply to pass a const char * to its constructor. For example, the following code creates a byte array of size 5 containing the data "Hello":
ba("Hello");
Although the () is 5, the byte array also maintains an extra '\0' character at the end so that if a function is used that asks for a pointer to the underlying data (e.g. a call to ()), the data pointed to is guaranteed to be '\0'-terminated.
makes a deep copy of the const char * data, so you can modify it later without experiencing side effects. (If for performance reasons you don't want to take a deep copy of the character data, use () instead.)
Another approach is to set the size of the array using () and to initialize the data byte per byte.
uses 0-based indexes, just like C++ arrays. To access the byte at a particular index position, you can use operator[](). On non-const byte arrays, operator[]() returns a reference to a byte that can be used on the left side of an assignment. For example:
ba.resize(5);
ba[0] = 0x3c;
ba[1] = 0xb8;
ba[2] = 0x64;
ba[3] = 0x18;
ba[4] = 0xca;
For read-only access, an alternative syntax is to use ():
for (int i = 0; i & ba.size(); ++i) {
if (ba.at(i) &= 'a' && ba.at(i) &= 'f')
cout && "Found character in range [a-f]" &&
() can be faster than operator[](), because it never causes a
To extract many bytes at a time, use (), (), or ().
can embed '\0' bytes. The () function always returns the size of the whole array, including embedded '\0' bytes. If you want to obtain the length of the data up to and excluding the first '\0' character, call () on the byte array.
After a call to (), newly allocated bytes have undefined values. To set all the bytes to a particular value, call ().
To obtain a pointer to the actual character data, call () or (). These functions return a pointer to the beginning of the data. The pointer is guaranteed to remain valid until a non-const function is called on the . It is also guaranteed that the data ends with a '\0' byte unless the
was created from a . This '\0' byte is automatically provided by
and is not counted in ().
provides the following basic functions for modifying the byte data: (), (), (), (), and (). For example:
x.prepend("rock ");
x.append(" roll");
x.replace(5, 3, "&");
The () and () functions' first two arguments are the position from which to start erasing and the number of bytes that should be erased.
When you () data to a non-empty array, the array will be reallocated and the new data copied to it. You can avoid this behavior by calling (), which preallocates a certain amount of memory. You can also call () to find out how much memory
actually allocated. Data appended to an empty array is not copied.
A frequent requirement is to remove whitespace characters from a byte array ('\n', '\t', ' ', etc.). If you want to remove whitespace from both ends of a , use (). If you want to remove whitespace from both ends and replace multiple consecutive whitespaces with a single space character within the byte array, use ().
If you want to find all occurrences of a particular character or substring in a , use () or (). The former searches forward starting from a given index position, the latter searches backward. Both return the index position of the character or subst otherwise, they return -1. For example, here's a typical loop that finds all occurrences of a particular substring:
ba("We must be &b&bold&/b&, very &b&bold&/b&");
int j = 0;
while ((j = ba.indexOf("&b&", j)) != -1) {
cout && "Found &b& tag at index position " && j &&
If you simply want to check whether a
contains a particular character or substring, use (). If you want to find out how many times a particular character or substring occurs in the byte array, use (). If you want to replace all occurrences of a particular value with another, use one of the two-parameter () overloads.
QByteArrays can be compared using overloaded operators such as operator&(), operator&=(), operator==(), operator&=(), and so on. The comparison is based exclusively on the numeric values of the characters and is very fast, but is not what a human would expect. () is a better choice for sorting user-interface strings.
For historical reasons,
distinguishes between a null byte array and an empty byte array. A null byte array is a byte array that is initialized using 's default constructor or by passing (const char *)0 to the constructor. An empty byte array is any byte array with size 0. A null byte array is always empty, but an empty byte array isn't necessarily null:
().isNull();
().isEmpty();
("").isNull();
("").isEmpty();
("abc").isNull();
("abc").isEmpty();
All functions except () treat null byte arrays the same as empty byte arrays. For example, () returns a pointer to a '\0' character for a null byte array (not a null pointer), and () compares equal to (""). We recommend that you always use () and avoid ().
Notes on Locale
Number-String Conversions
Functions that perform conversions between numeric data types and strings are performed in the C locale, irrespective of the user's locale settings. Use
to perform locale-aware conversions between numbers and strings.
8-bit Character Comparisons
In , the notion of uppercase and lowercase and of which character is greater than or less than another character is locale dependent. This affects functions that support a case insensitive option or that compare or lowercase or uppercase their arguments. Case insensitive operations and comparisons will be accurate if both strings contain only ASCII characters. (If $LC_CTYPE is set, most Unix systems do "the right thing".) Functions that this affects include (), (), (), operator&(), operator&=(), operator&(), operator&=(), () and ().
This issue does not apply to QStrings since they represent characters using Unicode.
Member Function Documentation
QByteArray::QByteArray()
Constructs an empty byte array.
See also ().
QByteArray::QByteArray(const char * str)
Constructs a byte array initialized with the string str.
makes a deep copy of the string data.
QByteArray::QByteArray(const char * data, int size)
Constructs a byte array containing the first size bytes of array data.
If data is 0, a null byte array is constructed.
makes a deep copy of the string data.
See also ().
QByteArray::QByteArray(int size, char ch)
Constructs a byte array of size size with every byte set to character ch.
See also ().
QByteArray::QByteArray(const
Constructs a copy of other.
This operation takes , because
is . This makes returning a
from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), taking .
See also ().
QByteArray::~QByteArray()
Destroys the byte array.
& QByteArray::append(const
Appends the byte array ba onto the end of this byte array.
x("free");
x.append(y);
This is the same as insert((), ba).
class. Consequently, if this is an empty , then this will just share the data held in ba. In this case, no copying of data is done, taking . If a shared instance is modified, it will be copied (copy-on-write), taking .
If this is not an empty , a deep copy of the data is performed, taking .
This operation typically does not suffer from allocation overhead, because
preallocates extra space at the end of the data so that it may grow without reallocating for each append operation.
See also (), (), and ().
& QByteArray::append(const
This is an overloaded function.
Appends the string str to this byte array. The Unicode data is converted into 8-bit characters using ().
contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining QT_NO_CAST_TO_ASCII when you compile your applications. You then need to call () (or () or () or ()) explicitly if you want to convert the data to const char *.
& QByteArray::append(const char * str)
This is an overloaded function.
Appends the string str to this byte array.
& QByteArray::append(const char * str, int len)
This function overloads ().
Appends the first len characters of the string str to this byte array and returns a reference to this byte array.
If len is negative, the length of the string will be determined automatically using (). If len is zero or str is null, nothing is appended to the byte array. Ensure that len is not longer than str.
& QByteArray::append(char ch)
This is an overloaded function.
Appends the character ch to this byte array.
char QByteArray::at(int i) const
Returns the character at index position i in the byte array.
i must be a valid index position in the byte array (i.e., 0 &= i & ()).
See also ().
int QByteArray::capacity() const
Returns the maximum number of bytes that can be stored in the byte array without forcing a reallocation.
The sole purpose of this function is to provide a means of fine tuning 's memory usage. In general, you will rarely ever need to call this function. If you want to know how many bytes are in the byte array, call ().
See also () and ().
void QByteArray::chop(int n)
Removes n bytes from the end of the byte array.
If n is greater than (), the result is an empty byte array.
ba("STARTTLS\r\n");
ba.chop(2);
See also (), (), and ().
void QByteArray::clear()
Clears the contents of the byte array and makes it empty.
See also () and ().
const char * QByteArray::constData() 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 unless the
object was created from raw data. The pointer remains valid as long as the byte array isn't reallocated or destroyed.
This function is mostly useful to pass a byte array to a function that accepts a const char *.
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 (), (), and ().
bool QByteArray::contains(const
& ba) const
Returns true if the byte array contains an occurrence of the byte array ba; otherwise returns false.
See also () and ().
bool QByteArray::contains(const char * str) const
This is an overloaded function.
Returns true if the byte array contains the string str; otherwise returns false.
bool QByteArray::contains(char ch) const
This is an overloaded function.
Returns true if the byte array contains the character ch; otherwise returns false.
int QByteArray::count(const
& ba) const
Returns the number of (potentially overlapping) occurrences of byte array ba in this byte array.
See also () and ().
int QByteArray::count(const char * str) const
This is an overloaded function.
Returns the number of (potentially overlapping) occurrences of string str in the byte array.
int QByteArray::count(char ch) const
This is an overloaded function.
Returns the number of occurrences of character ch in the byte array.
See also () and ().
int QByteArray::count() const
This is an overloaded function.
Same as ().
char * QByteArray::data()
Returns a pointer to the data stored in the byte array. The pointer can be used to access and modify the bytes that compose the array. The data is '\0'-terminated, i.e. the number of bytes in the returned character string is () + 1 for the '\0' terminator.
ba("Hello world");
char *data = ba.data();
while (*data) {
cout && "[" && *data && "]" &&
The pointer remains valid as long as the byte array isn't reallocated or destroyed. For read-only access, () is faster because it never causes a
This function is mostly useful to pass a byte array to a function that accepts a const char *.
The following example makes a copy of the char* returned by data(), but it will corrupt the heap and cause a crash because it does not allocate a byte for the '\0' at the end:
tmp = "test";
text = tmp.toLocal8Bit();
char *data = new char[text.size()]
strcpy(data, text.data());
This one allocates the correct amount of space:
tmp = "test";
text = tmp.toLocal8Bit();
char *data = new char[text.size() + 1]
strcpy(data, text.data());
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 () and ().
const char * QByteArray::data() const
This is an overloaded function.
bool QByteArray::endsWith(const
& ba) const
Returns true if this byte array ends with byte array ba; otherwise returns false.
url("/index.html");
if (url.endsWith(".html"))
See also () and ().
bool QByteArray::endsWith(const char * str) const
This is an overloaded function.
Returns true if this byte array ends with string str; otherwise returns false.
bool QByteArray::endsWith(char ch) const
This is an overloaded function.
Returns true if this byte array ends with character ch; otherwise returns false.
& QByteArray::fill(char ch, int size = -1)
Sets every byte in the byte array to character ch. If size is different from -1 (the default), the byte array is resized to size size beforehand.
ba("Istambul");
ba.fill('o');
ba.fill('X', 2);
See also ().
QByteArray::fromBase64(const
Returns a decoded copy of the Base64 array base64. Input is not
invalid characters in the input are skipped, enabling the decoding process to continue with subsequent characters.
For example:
text = ::fromBase64("UXQgaXMgZ3JlYXQh");
text.data();
The algorithm used to decode Base64-encoded data is defined in .
See also ().
QByteArray::fromHex(const
& hexEncoded)
Returns a decoded copy of the hex encoded array hexEncoded. Input is not
invalid characters in the input are skipped, enabling the decoding process to continue with subsequent characters.
For example:
text = ::fromHex("");
text.data();
See also ().
QByteArray::fromPercentEncoding(const
& input, char percent = '%')
Returns a decoded copy of the URI/URL-style percent-encoded input. The percent parameter allows you to replace the '%' character for another (for instance, '_' or '=').
For example:
text = ::fromPercentEncoding("Qt%20is%20great%33");
This function was introduced in
See also () and ().
QByteArray::fromRawData(const char * data, int size)
Constructs a
that uses the first size bytes of the data array. The bytes are not copied. The
will contain the data pointer. The caller guarantees that data will not be deleted or modified as long as this
and any copies of it exist that have not been modified. In other words, because
class and the instance returned by this function contains the data pointer, the caller must not delete data or modify it directly as long as the returned
and any copies exist. However,
does not take ownership of data, so the
destructor will never delete the raw data, even when the last
referring to data is destroyed.
A subsequent attempt to modify the contents of the returned
or any copy made from it will cause it to create a deep copy of the data array before doing the modification. This ensures that the raw data array itself will never be modified by .
Here is an example of how to read data using a
on raw data in memory without copying the raw data into a :
static const char mydata[] = {
0x00, 0x00, 0x03, 0x84, 0x78, 0x9c, 0x3b, 0x76,
0xec, 0x18, 0xc3, 0x31, 0x0a, 0xf1, 0xcc, 0x99,
0x6d, 0x5b
data = ::fromRawData(mydata, sizeof(mydata));
in(&data, ::ReadOnly);
Warning: A byte array created with fromRawData() is not null-terminated, unless the raw data contains a 0 character at position size. While that does not matter for
or functions like (), passing the byte array to a function accepting a const char * expected to be '\0'-terminated will fail.
See also (), (), and ().
int QByteArray::indexOf(const
& ba, int from = 0) const
Returns the index position of the first occurrence of the byte array ba in this byte array, searching forward from index position from. Returns -1 if ba could not be found.
x("sticky question");
x.indexOf(y);
x.indexOf(y, 1);
x.indexOf(y, 10);
x.indexOf(y, 11);
See also (), (), and ().
int QByteArray::indexOf(const
& str, int from = 0) const
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 ().
contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining QT_NO_CAST_TO_ASCII when you compile your applications. You then need to call () (or () or () or ()) explicitly if you want to convert the data to const char *.
int QByteArray::indexOf(const char * str, int from = 0) const
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.
int QByteArray::indexOf(char ch, int from = 0) const
This is an overloaded function.
Returns the index position of the first occurrence of the character ch in the byte array, searching forward from index position from. Returns -1 if ch could not be found.
ba("ABCBA");
ba.indexOf("B");
ba.indexOf("B", 1);
ba.indexOf("B", 2);
ba.indexOf("X");
See also () and ().
& QByteArray::insert(int i, const
Inserts the byte array ba at index position i and returns a reference to this byte array.
ba("Meal");
ba.insert(1, ("ontr"));
See also (), (), (), and ().
& QByteArray::insert(int i, const
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 ().
If i is greater than (), the array is first extended using ().
contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining QT_NO_CAST_TO_ASCII when you compile your applications. You then need to call () (or () or () or ()) explicitly if you want to convert the data to const char *.
& QByteArray::insert(int i, const char * str)
This is an overloaded function.
Inserts the string str at position i in the byte array.
If i is greater than (), the array is first extended using ().
& QByteArray::insert(int i, const char * str, int len)
This is an overloaded function.
Inserts len bytes of the string str at position i in the byte array.
If i is greater than (), the array is first extended using ().
This function was introduced in
& QByteArray::insert(int i, char ch)
This is an overloaded function.
Inserts character ch at index position i in the byte array. If i is greater than (), the array is first extended using ().
bool QByteArray::isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
().isEmpty();
("").isEmpty();
("abc").isEmpty();
See also ().
bool QByteArray::isNull() const
Returns true if thi otherwise returns false.
().isNull();
("").isNull();
("abc").isNull();
Qt makes a distinction between null byte arrays and empty byte arrays for historical reasons. For most applications, what matters is whether or not a byte array contains any data, and this can be determined using ().
See also ().
int QByteArray::lastIndexOf(const
& ba, int from = -1) const
Returns the index position of the last occurrence of the byte array ba in this byte array, searching backward from index position from. If from is -1 (the default), the search starts at the last byte. Returns -1 if ba could not be found.
x("crazy azimuths");
x.lastIndexOf(y);
x.lastIndexOf(y, 6);
x.lastIndexOf(y, 5);
x.lastIndexOf(y, 1);
See also (), (), and ().
int QByteArray::lastIndexOf(const
& str, int from = -1) const
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 (() - 1) byte. Returns -1 if str could not be found.
The Unicode data is converted into 8-bit characters using ().
contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining QT_NO_CAST_TO_ASCII when you compile your applications. You then need to call () (or () or () or ()) explicitly if you want to convert the data to const char *.
int QByteArray::lastIndexOf(const char * str, int from = -1) const
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 (() - 1) byte. Returns -1 if str could not be found.
int QByteArray::lastIndexOf(char ch, int from = -1) const
This is an overloaded function.
Returns the index position of the last occurrence of character ch in the byte array, searching backward from index position from. If from is -1 (the default), the search starts at the last (() - 1) byte. Returns -1 if ch could not be found.
ba("ABCBA");
ba.lastIndexOf("B");
ba.lastIndexOf("B", 3);
ba.lastIndexOf("B", 2);
ba.lastIndexOf("X");
See also () and ().
QByteArray::left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
The entire byte array is returned if len is greater than ().
x("Pineapple");
y = x.left(4);
See also (), (), (), and ().
QByteArray::leftJustified(int width, char fill = ' ', bool truncate = false) const
Returns a byte array of size width that contains this byte array padded by the fill character.
If truncate is false and the () of the byte array is more than width, then the returned byte array is a copy of this byte array.
If truncate is true and the () of the byte array is more than width, then any bytes in a copy of the byte array after position width are removed, and the copy is returned.
x("apple");
y = x.leftJustified(8, '.');
See also ().
int QByteArray::length() const
Same as ().
QByteArray::mid(int pos, int len = -1) const
Returns a byte array containing len bytes from this byte array, starting at position pos.
If len is -1 (the default), or pos + len &= (), returns a byte array containing all bytes starting at position pos until the end of the byte array.
x("Five pineapples");
y = x.mid(5, 4);
z = x.mid(5);
See also () and ().
QByteArray::number(int n, int base = 10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default). The base can be any value between 2 and 36.
int n = 63;
::number(n);
::number(n, 16);
::number(n, 16).toUpper();
Note: The format of the num the default C locale is used irrespective of the user's locale.See also () and ().
QByteArray::number( n, int base = 10)
This is an overloaded function.
See also ().
QByteArray::number( n, int base = 10)
This is an overloaded function.
See also ().
QByteArray::number( n, int base = 10)
This is an overloaded function.
See also ().
QByteArray::number(double n, char f = 'g', int prec = 6)
This is an overloaded function.
Returns a byte array that contains the printed value of n, formatted in format f with precision prec.
Argument n is formatted according to the f format specified, which is g by default, and can be any of the following:
FormatMeaning
eformat as [-]9.9e[+|-]999
Eformat as [-]9.9E[+|-]999
fformat as [-]9.9
guse e or f format, whichever is the most concise
Guse E or f format, whichever is the most concise
With 'e', 'E', and 'f', prec is the number of digits after the decimal point. With 'g' and 'G', prec is the maximum number of significant digits (trailing zeroes are omitted).
ba = ::number(12.3456, 'E', 3);
Note: The format of the num the default C locale is used irrespective of the user's locale.See also ().
& QByteArray::prepend(const
Prepends the byte array ba to this byte array and returns a reference to this byte array.
x("ship");
x.prepend(y);
This is the same as insert(0, ba).
class. Consequently, if this is an empty , then this will just share the data held in ba. In this case, no copying of data is done, taking . If a shared instance is modified, it will be copied (copy-on-write), taking .
If this is not an empty , a deep copy of the data is performed, taking .
See also () and ().
& QByteArray::prepend(const char * str)
This is an overloaded function.
Prepends the string str to this byte array.
& QByteArray::prepend(const char * str, int len)
This is an overloaded function.
Prepends len bytes of the string str to this byte array.
This function was introduced in
& QByteArray::prepend(char ch)
This is an overloaded function.
Prepends the character ch to this byte array.
void QByteArray::push_back(const
This function is provided for STL compatibility. It is equivalent to append(other).
void QByteArray::push_back(const char * str)
This is an overloaded function.
Same as append(str).
void QByteArray::push_back(char ch)
This is an overloaded function.
Same as append(ch).
void QByteArray::push_front(const
This function is provided for STL compatibility. It is equivalent to prepend(other).
void QByteArray::push_front(const char * str)
This is an overloaded function.
Same as prepend(str).
void QByteArray::push_front(char ch)
This is an overloaded function.
Same as prepend(ch).
& QByteArray::remove(int pos, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the array.
If pos is out of range, nothing happens. If pos is valid, but pos + len is larger than the size of the array, the array is truncated at position pos.
ba("Montreal");
ba.remove(1, 4);
See also () and ().
QByteArray::repeated(int times) const
Returns a copy of this byte array repeated the specified number of times.
If times is less than 1, an empty byte array is returned.
ba.repeated(4);
This function was introduced in
& QByteArray::replace(int pos, int len, const
Replaces len bytes from index position pos with the byte array after, and returns a reference to this byte array.
x("Say yes!");
x.replace(4, 3, y);
See also () and ().
& QByteArray::replace(int pos, int len, const char * after)
This is an overloaded function.
Replaces len bytes from index position pos with the zero terminated string after.
Notice: this can change the length of the byte array.
& QByteArray::replace(int pos, int len, const char * after, int alen)
This is an overloaded function.
Replaces len bytes from index position pos with alen bytes from the string after. after is allowed to have '\0' characters.
This function was introduced in
& QByteArray::replace(const
& before, const
This is an overloaded function.
Replaces every occurrence of the byte array before with the byte array after.
ba("colour behaviour flavour neighbour");
ba.replace(("ou"), ("o"));
& QByteArray::replace(const char * before, const
This is an overloaded function.
Replaces every occurrence of the string before with the byte array after.
& QByteArray::replace(const char * before, int bsize, const char * after, int asize)
This is an overloaded function.
Replaces every occurrence of the string before with the string after. Since the sizes of the strings are given by bsize and asize, they may contain zero characters and do not need to be zero-terminated.
& QByteArray::replace(const
& before, const char * after)
This is an overloaded function.
Replaces every occurrence of the byte array before with the string after.
& QByteArray::replace(const
& before, const
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 ().
contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining QT_NO_CAST_TO_ASCII when you compile your applications. You then need to call () (or () or () or ()) explicitly if you want to convert the data to const char *.
& QByteArray::replace(const
& before, const char * after)
This is an overloaded function.
Replaces every occurrence of the string before with the string after.
& QByteArray::replace(const char * before, const char * after)
This is an overloaded function.
Replaces every occurrence of the string before with the string after.
& QByteArray::replace(char before, const
This is an overloaded function.
Replaces every occurrence of the character before with the byte array after.
& QByteArray::replace(char before, const
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 ().
contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining QT_NO_CAST_TO_ASCII when you compile your applications. You then need to call () (or () or () or ()) explicitly if you want to convert the data to const char *.
& QByteArray::replace(char before, const char * after)
This is an overloaded function.
Replaces every occurrence of the character before with the string after.
& QByteArray::replace(char before, char after)
This is an overloaded function.
Replaces every occurrence of the character before with the character after.
void QByteArray::reserve(int size)
Attempts to allocate memory for at least size bytes. If you know in advance how large the byte array will be, you can call this function, and if you call () often you are likely to get better performance. If size is an underestimate, the worst that will happen is that the
will be a bit slower.
The sole purpose of this function is to provide a means of fine tuning 's memory usage. In general, you will rarely ever need to call this function. If you want to change the size of the byte array, call ().
See also () and ().
void QByteArray::resize(int size)
Sets the size of the byte array to size bytes.
If size is greater than the current size, the byte array is extended to make it size bytes with the extra bytes added to the end. The new bytes are uninitialized.
If size is less than the current size, bytes are removed from the end.
See also () and ().
QByteArray::right(int len) const
Returns a byte array that contains the rightmost len bytes of this byte array.
The entire byte array is returned if len is greater than ().
x("Pineapple");
y = x.right(5);
See also (), (), and ().
QByteArray::rightJustified(int width, char fill = ' ', bool truncate = false) const
Returns a byte array of size width that contains the fill character followed by this byte array.
If truncate is false and the size of the byte array is more than width, then the returned byte array is a copy of this byte array.
If truncate is true and the size of the byte array is more than width, then the resulting byte array is truncated at position width.
x("apple");
y = x.rightJustified(8, '.');
See also ().
& QByteArray::setNum(int n, int base = 10)
Sets the byte array to the printed value of n in base base (10 by default) and returns a reference to the byte array. The base can be any value between 2 and 36.
int n = 63;
ba.setNum(n);
ba.setNum(n, 16);
Note: The format of the num the default C locale is used irrespective of the user's locale.See also () and ().
& QByteArray::setNum( n, int base = 10)
This is an overloaded function.
See also ().
& QByteArray::setNum(short n, int base = 10)
This is an overloaded function.
See also ().
& QByteArray::setNum( n, int base = 10)
This is an overloaded function.
See also ().
& QByteArray::setNum( n, int base = 10)
This is an overloaded function.
See also ().
& QByteArray::setNum( n, int base = 10)
This is an overloaded function.
See also ().
& QByteArray::setNum(double n, char f = 'g', int prec = 6)
This is an overloaded function.
Sets the byte array to the printed value of n, formatted in format f with precision prec, and returns a reference to the byte array.
The format f can be any of the following:
FormatMeaning
eformat as [-]9.9e[+|-]999
Eformat as [-]9.9E[+|-]999
fformat as [-]9.9
guse e or f format, whichever is the most concise
Guse E or f format, whichever is the most concise
With 'e', 'E', and 'f', prec is the number of digits after the decimal point. With 'g' and 'G', prec is the maximum number of significant digits (trailing zeroes are omitted).
Note: The format of the num the default C locale is used irrespective of the user's locale.See also ().
& QByteArray::setNum(float n, char f = 'g', int prec = 6)
This is an overloaded function.
Sets the byte array to the printed value of n, formatted in format f with precision prec, and returns a reference to the byte array.
Note: The format of the num the default C locale is used irrespective of the user's locale.See also ().
& QByteArray::setRawData(const char * data,
Resets the
to use the first size bytes of the data array. The bytes are not copied. The
will contain the data pointer. The caller guarantees that data will not be deleted or modified as long as this
and any copies of it exist that have not been modified.
This function can be used instead of () to re-use existings
objects to save memory re-allocations.
This function was introduced in
See also (), (), and ().
QByteArray::simplified() const
Returns a byte array that has whitespace removed from the start and the end, and which has each sequence of internal whitespace replaced with a single space.
Whitespace means any character for which the standard C++ isspace() function returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.
lots\t of\nwhitespace\r\n ");
ba = ba.simplified();
See also ().
int QByteArray::size() const
Returns the number of bytes in this byte array.
The last byte in the byte array is at position size() - 1. In addition,
ensures that the byte at position size() is always '\0', so that you can use the return value of () and () as arguments to functions that expect '\0'-terminated strings. If the
object was created from a
that didn't include the trailing null-termination character then
doesn't add it automaticall unless the
is created.
ba("Hello");
int n = ba.size();
ba.data()[0];
ba.data()[4];
ba.data()[5];
See also () and ().
&& QByteArray::split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays. If sep does not match anywhere in the byte array, split() returns a single-element list containing this byte array.
void QByteArray::squeeze()
Releases any memory not required to store the array's data.
The sole purpose of this function is to provide a means of fine tuning 's memory usage. In general, you will rarely ever need to call this function.
See also () and ().
bool QByteArray::startsWith(const
& ba) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
url("ftp://ftp./");
if (url.startsWith("ftp:"))
See also () and ().
bool QByteArray::startsWith(const char * str) const
This is an overloaded function.
Returns true if this byte array starts with string str; otherwise returns false.
bool QByteArray::startsWith(char ch) const
This is an overloaded function.
Returns true if this byte array starts with character ch; otherwise returns false.
void QByteArray::swap( & other)
Swaps byte array other with this byte array. This operation is very fast and never fails.
This function was introduced in
QByteArray::toBase64() const
Returns a copy of the byte array, encoded as Base64.
text("Qt is great!");
text.toBase64();
The algorithm used to encode Base64-encoded data is defined in .
See also ().
double QByteArray::toDouble(bool * ok = 0) const
Returns the byte array converted to a double value.
Returns 0.0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
string("1234.56");
double a = string.toDouble();
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.See also ().
float QByteArray::toFloat(bool * ok = 0) const
Returns the byte array converted to a float value.
Returns 0.0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.See also ().
QByteArray::toHex() const
Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.
See also ().
int QByteArray::toInt(bool * ok = 0, int base = 10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be between 2 and 36, or 0.
If base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assum if it begins with "0", it is otherwise it is assumed to be decimal.
Returns 0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
str("FF");
int hex = str.toInt(&ok, 16);
int dec = str.toInt(&ok, 10);
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.See also ().
long QByteArray::toLong(bool * ok = 0, int base = 10) const
Returns the byte array converted to a long int using base base, which is 10 by default and must be between 2 and 36, or 0.
If base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assum if it begins with "0", it is otherwise it is assumed to be decimal.
Returns 0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
str("FF");
long hex = str.toLong(&ok, 16);
long dec = str.toLong(&ok, 10);
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.This function was introduced in
See also ().
QByteArray::toLongLong(bool * ok = 0, int base = 10) const
Returns the byte array converted to a long long using base base, which is 10 by default and must be between 2 and 36, or 0.
If base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assum if it begins with "0", it is otherwise it is assumed to be decimal.
Returns 0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.See also ().
QByteArray::toLower() const
Returns a lowercase copy of the byte array. The bytearray is interpreted as a Latin-1 encoded string.
x("Qt by NOKIA");
y = x.toLower();
See also () and .
QByteArray::toPercentEncoding(const
& exclude = QByteArray(), const
& include = QByteArray(), char percent = '%') const
Returns a URI/URL-style percent-encoded copy of this byte array. The percent parameter allows you to override the default '%' character for another.
By default, this function will encode all characters that are not one of the following:
ALPHA ("a" to "z" and "A" to "Z") / DIGIT (0 to 9) / "-" / "." / "_" / "~"
To prevent characters from being encoded pass them to exclude. To force characters to be encoded pass them to include. The percent character is always encoded.
text = "{a fishy string?}";
ba = text.toPercentEncoding("{}", "s");
(ba.constData());
The hex encoding uses the numbers 0-9 and the uppercase letters A-F.
This function was introduced in
See also () and ().
short QByteArray::toShort(bool * ok = 0, int base = 10) const
Returns the byte array converted to a short using base base, which is 10 by default and must be between 2 and 36, or 0.
If base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assum if it begins with "0", it is otherwise it is assumed to be decimal.
Returns 0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.See also ().
QByteArray::toUInt(bool * ok = 0, int base = 10) const
Returns the byte array converted to an unsigned int using base base, which is 10 by default and must be between 2 and 36, or 0.
If base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assum if it begins with "0", it is otherwise it is assumed to be decimal.
Returns 0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.See also ().
QByteArray::toULong(bool * ok = 0, int base = 10) const
Returns the byte array converted to an unsigned long int using base base, which is 10 by default and must be between 2 and 36, or 0.
If base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assum if it begins with "0", it is otherwise it is assumed to be decimal.
Returns 0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.This function was introduced in
See also ().
QByteArray::toULongLong(bool * ok = 0, int base = 10) const
Returns the byte array converted to an unsigned long long using base base, which is 10 by default and must be between 2 and 36, or 0.
If base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assum if it begins with "0", it is otherwise it is assumed to be decimal.
Returns 0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.See also ().
QByteArray::toUShort(bool * ok = 0, int base = 10) const
Returns the byte array converted to an unsigned short using base base, which is 10 by default and must be between 2 and 36, or 0.
If base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assum if it begins with "0", it is otherwise it is assumed to be decimal.
Returns 0 if the conversion fails.
If ok is not 0: if a conversion error occurs, *ok otherwise *ok is set to true.
Note: The conversion of the number is performed in the default C locale, irrespective of the user's locale.See also ().
QByteArray::toUpper() const
Returns an uppercase copy of the byte array. The bytearray is interpreted as a Latin-1 encoded string.
x("Qt by NOKIA");
y = x.toUpper();
See also () and .
QByteArray::trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
Whitespace means any character for which the standard C++ isspace() function returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.
lots\t of\nwhitespace\r\n ");
ba = ba.trimmed();
Unlike (), trimmed() leaves internal whitespace alone.
See also ().
void QByteArray::truncate(int pos)
Truncates the byte array at index position pos.
If pos is beyond the end of the array, nothing happens.
ba("Stockholm");
ba.truncate(5);
See also (), (), and ().
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.
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 ().
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.
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 ().
bool QByteArray::operator!=(const
& str) const
Returns true if this byte array is not equal to string str; otherwise returns false.
The Unicode data is converted into 8-bit characters using ().
The comparison is case sensitive.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. You then need to call (), (), (), or () explicitly if you want to convert the byte array to a
before doing the comparison.
& QByteArray::operator+=(const
Appends the byte array ba onto the end of this byte array and returns a reference to this byte array.
x("free");
class. Consequently, if this is an empty , then this will just share the data held in ba. In this case, no copying of data is done, taking . If a shared instance is modified, it will be copied (copy-on-write), taking .
If this is not an empty , a deep copy of the data is performed, taking .
This operation typically does not suffer from allocation overhead, because
preallocates extra space at the end of the data so that it may grow without reallocating for each append operation.
See also () and ().
& QByteArray::operator+=(const
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 ().
contains non-ASCII Unicode characters, using this operator can lead to loss of information. You can disable this operator by defining QT_NO_CAST_TO_ASCII when you compile your applications. You then need to call () (or () or () or ()) explicitly if you want to convert the data to const char *.
& QByteArray::operator+=(const char * str)
This is an overloaded function.
Appends the string str onto the end of this byte array and returns a reference to this byte array.
& QByteArray::operator+=(char ch)
This is an overloaded function.
Appends the character ch onto the end of this byte array and returns a reference to this byte array.
bool QByteArray::operator&(const
& str) const
Returns true if this byte array is lexically less than string str; otherwise returns false.
The Unicode data is converted into 8-bit characters using ().
The comparison is case sensitive.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. You then need to call (), (), (), or () explicitly if you want to convert the byte array to a
before doing the comparison.
bool QByteArray::operator&=(const
& str) const
Returns true if this byte array is lexically less than or equal to string str; otherwise returns false.
The Unicode data is converted into 8-bit characters using ().
The comparison is case sensitive.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. You then need to call (), (), (), or () explicitly if you want to convert the byte array to a
before doing the comparison.
& QByteArray::operator=(const
Assigns other to this byte array and returns a reference to this byte array.
& QByteArray::operator=( && other)
& QByteArray::operator=(const char * str)
This is an overloaded function.
Assigns str to this byte array.
bool QByteArray::operator==(const
& str) const
Returns true if this byte array is equal to string str; otherwise returns false.
The Unicode data is converted into 8-bit characters using ().
The comparison is case sensitive.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. You then need to call (), (), (), or () explicitly if you want to convert the byte array to a
before doing the comparison.
bool QByteArray::operator&(const
& str) const
Returns true if this byte array is lexically greater than string str; otherwise returns false.
The Unicode data is converted into 8-bit characters using ().
The comparison is case sensitive.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. You then need to call (), (), (), or () explicitly if you want to convert the byte array to a
before doing the comparison.
bool QByteArray::operator&=(const
& str) const
Returns true if this byte array is greater than or equal to string str; otherwise returns false.
The Unicode data is converted into 8-bit characters using ().
The comparison is case sensitive.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. You then need to call (), (), (), or () explicitly if you want to convert the byte array to a
before doing the comparison.
QByteRef QByteArray::operator[](int i)
Returns the byte at index position i as a modifiable reference.
If an assignment is made beyond the end of the byte array, the array is extended with () before the assignment takes place.
for (int i = 0; i & 10; ++i)
ba[i] = 'A' +
The return value is of type QByteRef, a helper class for . When you get an object of type QByteRef, you can use it as if it were a char &. If you assign to it, the assignment will apply to the character in the
from which you got the reference.
See also ().
char QByteArray::operator[](int i) const
This is an overloaded function.
Same as at(i).
QByteRef QByteArray::operator[]( i)
This is an overloaded function.
char QByteArray::operator[]( i) const
This is an overloaded function.
Related Non-Members
qChecksum(const char * data,
Returns the CRC-16 checksum of the first len bytes of data.
The checksum is independent of the byte order (endianness).
Note: This function is a 16-bit cache conserving (16 entry table) implementation of the CRC-16-CCITT algorithm.
qCompress(const
& data, int compressionLevel = -1)
Compresses the data byte array and returns the compressed data in a new byte array.
The compressionLevel parameter specifies how much compression should be used. Valid values are between 0 and 9, with 9 corresponding to the greatest compression (i.e. smaller compressed data) at the cost of using a slower algorithm. Smaller values (8, 7, ..., 1) provide successively less compression at slightly faster speeds. The value 0 corresponds to no compression at all. The default value is -1, which specifies zlib's default compression.
See also ().
qCompress(const
* data, int nbytes, int compressionLevel = -1)
This is an overloaded function.
Compresses the first nbytes of data and returns the compressed data in a new byte array.
qUncompress(const
Uncompresses the data byte array and returns a new byte array with the uncompressed data.
Returns an empty
if the input data was corrupt.
This function will uncompress data compressed with () from this and any earlier Qt version, back to Qt 3.1 when this feature was added.
Note: If you want to use this function to uncompress external data that was compressed using zlib, you first need to prepend a four byte header to the byte array containing the data. The header must contain the expected length (in bytes) of the uncompressed data, expressed as an unsigned, big-endian, 32-bit integer.
See also ().
qUncompress(const
* data, int nbytes)
This is an overloaded function.
Uncompresses the first nbytes of data and returns a new byte array with the uncompressed data.
int qsnprintf(char * str, size_t n, const char * fmt, ...)
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 () to format a string instead.
See also () and ().
int qstrcmp(const char * str1, const char * str2)
A safe strcmp() function.
Compares str1 and str2. Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.
Special case 1: Returns 0 if str1 and str2 are both 0.
Special case 2: Returns an arbitrary non-zero value if str1 is 0 or str2 is 0 (but not both).
See also (), (), (), and .
char * qstrcpy(char * dst, const char * src)
Copies all the characters up to and including the '\0' from src into dst and returns a pointer to dst. If src is 0, it immediately returns 0.
This function assumes that dst is large enough to hold the contents of src.
See also ().
char * qstrdup(const char * src)
Returns a duplicate string.
Allocates space for a copy of src, copies it, and returns a pointer to the copy. If src is 0, it immediately returns 0.
Ownership is passed to the caller, so the returned string must be deleted using delete[].
int qstricmp(const char * str1, const char * str2)
A safe stricmp() function.
Compares str1 and str2 ignoring the case of the characters. The encoding of the strings is assumed to be Latin-1.
Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.
Special case 1: Returns 0 if str1 and str2 are both 0.
Special case 2: Returns a random non-zero value if str1 is 0 or str2 is 0 (but not both).
See also (), (), (), and .
qstrlen(const char * str)
A safe strlen() function.
Returns the number of characters that precede the terminating '\0', or 0 if str is 0.
See also ().
int qstrncmp(const char * str1, const char * str2,
A safe strncmp() function.
Compares at most len bytes of str1 and str2.
Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.
Special case 1: Returns 0 if str1 and str2 are both 0.
Special case 2: Returns a random non-zero value if str1 is 0 or str2 is 0 (but not both).
See also (), (), (), and .
char * qstrncpy(char * dst, const char * src,
A safe strncpy() function.
Copies at most len bytes from src (stopping at len or the terminating '\0' whichever comes first) into dst and returns a pointer to dst. Guarantees that dst is '\0'-terminated. If src or dst is 0, returns 0 immediately.
This function assumes that dst is at least len characters long.
Note: When compiling with Visual C++ compiler version 14.00 (Visual C++ 2005) or later, internally the function strncpy_s will be used.See also ().
int qstrnicmp(const char * str1, const char * str2,
A safe strnicmp() function.
Compares at most len bytes of str1 and str2 ignoring the case of the characters. The encoding of the strings is assumed to be Latin-1.
Returns a negative value if str1 is less than str2, 0 if str1 is equal to str2 or a positive value if str1 is greater than str2.
Special case 1: Returns 0 if str1 and str2 are both 0.
Special case 2: Returns a random non-zero value if str1 is 0 or str2 is 0 (but not both).
See also (), (), (), and .
qstrnlen(const char * str,
A safe strnlen() function.
Returns the number of characters that precede the terminating '\0', but at most maxlen. If str is 0, returns 0.
This function was introduced in
See also ().
int qvsnprintf(char * str, size_t n, const char * fmt, va_list ap)
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 () instead.
See also () and ().
bool operator!=(const
& a1, const
This is an overloaded function.
Returns true if byte array a1 is not equal to byte array a2; otherwise returns false.
bool operator!=(const
& a1, const char * a2)
This is an overloaded function.
Returns true if byte array a1 is not equal to string a2; otherwise returns false.
bool operator!=(const char * a1, const
This is an overloaded function.
Returns true if string a1 is not equal to byte array a2; otherwise returns false.
operator+(const
& a1, const
Returns a byte array that is the result of concatenating byte array a1 and byte array a2.
See also ().
operator+(const
& a1, const char * a2)
This is an overloaded function.
Returns a byte array that is the result of concatenating byte array a1 and string a2.
operator+(const
& a1, char a2)
This is an overloaded function.
Returns a byte array that is the result of concatenating byte array a1 and character a2.
operator+(const char * a1, const
This is an overloaded function.
Returns a byte array that is the result of concatenating string a1 and byte array a2.
operator+(char a1, const
This is an overloaded function.
Returns a byte array that is the result of concatenating character a1 and byte array a2.
bool operator&(const
& a1, const
This is an overloaded function.
Returns true if byte array a1 is lexically less than byte array a2; otherwise returns false.
bool operator&(const
& a1, const char * a2)
This is an overloaded function.
Returns true if byte array a1 is lexically less than string a2; otherwise returns false.
bool operator&(const char * a1, const
This is an overloaded function.
Returns true if string a1 is lexically less than byte array a2; otherwise returns false.
& operator&&( & out, const
Writes byte array ba to the stream out and returns a reference to the stream.
See also .
bool operator&=(const
& a1, const
This is an overloaded function.
Returns true if byte array a1 is lexically less than or equal to byte array a2; otherwise returns false.
bool operator&=(const
& a1, const char * a2)
This is an overloaded function.
Returns true if byte array a1 is lexically less than or equal to string a2; otherwise returns false.
bool operator&=(const char * a1, const
This is an overloaded function.
Returns true if string a1 is lexically less than

我要回帖

更多关于 小数点处理 的文章

 

随机推荐