Member Function Documentation
QVarLengthArray::QVarLengthArray(int size = 0)
Constructs an array with an initial size of size elements.
If the value type is a primitive type (e.g., char, int, float) or a pointer type (e.g., QWidget *), the elements are not initialized. For other types, the elements are initialized with a default-constructed value.
QVarLengthArray::QVarLengthArray(const QVarLengthArray<T, Prealloc> & other)
Constructs a copy of other.
QVarLengthArray::~QVarLengthArray()
Destroys the array.
void QVarLengthArray::append(const T & t)
Appends item t to the array, extending the array if necessary.
See also removeLast().
void QVarLengthArray::append(const T * buf, int size)
Appends size amount of items referenced by buf to this array.
const T & QVarLengthArray::at(int i) const
Returns a reference to the item at index position i.
i must be a valid index position in the array (i.e., 0 <= i < size()).
See also value() and operator[]().
iterator QVarLengthArray::begin()
Returns an STL-style iterator pointing to the first item in the array.
This function was introduced in Qt 4.8.
See also constBegin() and end().
const_iterator QVarLengthArray::begin() const
This is an overloaded function.
This function was introduced in Qt 4.8.
int QVarLengthArray::capacity() const
Returns the maximum number of elements that can be stored in the array without forcing a reallocation.
The sole purpose of this function is to provide a means of fine tuning QVarLengthArray's memory usage. In general, you will rarely ever need to call this function. If you want to know how many items are in the array, call size().
See also reserve().
const_iterator QVarLengthArray::cbegin() const
Returns a const STL-style iterator pointing to the first item in the array.
This function was introduced in Qt 5.0.
See also begin() and cend().
const_iterator QVarLengthArray::cend() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the array.
This function was introduced in Qt 5.0.
See also cbegin() and end().
void QVarLengthArray::clear()
Removes all the elements from the array.
Same as resize(0).
const_iterator QVarLengthArray::constBegin() const
Returns a const STL-style iterator pointing to the first item in the array.
This function was introduced in Qt 4.8.
See also begin() and constEnd().
const T * QVarLengthArray::constData() const
Returns a const pointer to the data stored in the array. The pointer can be used to access the items in the array. The pointer remains valid as long as the array isn't reallocated.
This function is mostly useful to pass an array to a function that accepts a plain C++ array.
See also data() and operator[]().
const_iterator QVarLengthArray::constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the array.
This function was introduced in Qt 4.8.
See also constBegin() and end().
int QVarLengthArray::count() const
Same as size().
See also isEmpty() and resize().
T * QVarLengthArray::data()
Returns a pointer to the data stored in the array. The pointer can be used to access and modify the items in the array.
Example:
QVarLengthArray<int> array(10);
int *data = array.data();
for (int i = 0; i < 10; ++i)
data[i] = 2 * i;
The pointer remains valid as long as the array isn't reallocated.
This function is mostly useful to pass an array to a function that accepts a plain C++ array.
See also constData() and operator[]().
const T * QVarLengthArray::data() const
This is an overloaded function.
iterator QVarLengthArray::end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the array.
This function was introduced in Qt 4.8.
See also begin() and constEnd().
const_iterator QVarLengthArray::end() const
This is an overloaded function.
This function was introduced in Qt 4.8.
Removes the item pointed to by the iterator pos from the vector, and returns an iterator to the next item in the vector (which may be end()).
This function was introduced in Qt 4.8.
See also insert() and remove().
This is an overloaded function.
Removes all the items from begin up to (but not including) end. Returns an iterator to the same item that end referred to before the call.
This function was introduced in Qt 4.8.
T & QVarLengthArray::first()
Returns a reference to the first item in the array. The array must not be empty. If the array can be empty, check isEmpty() before calling this function.
See also last() and isEmpty().
const T & QVarLengthArray::first() const
This is an overloaded function.
void QVarLengthArray::insert(int i, const T & value)
Inserts value at index position i in the array. If i is 0, the value is prepended to the vector. If i is size(), the value is appended to the vector.
For large arrays, this operation can be slow (linear time), because it requires moving all the items at indexes i and above by one position further in memory. If you want a container class that provides a fast insert() function, use QLinkedList instead.
This function was introduced in Qt 4.8.
See also remove().
iterator QVarLengthArray::insert(iterator before, int count, const T & value)
Inserts count copies of value in front of the item pointed to by the iterator before. Returns an iterator pointing at the first of the inserted items.
This function was introduced in Qt 4.8.
void QVarLengthArray::insert(int i, int count, const T & value)
This is an overloaded function.
Inserts count copies of value at index position i in the vector.
This function was introduced in Qt 4.8.
iterator QVarLengthArray::insert(iterator before, const T & value)
This is an overloaded function.
Inserts value in front of the item pointed to by the iterator before. Returns an iterator pointing at the inserted item.
This function was introduced in Qt 4.8.
bool QVarLengthArray::isEmpty() const
Returns true if the array has size 0; otherwise returns false.
See also size() and resize().
T & QVarLengthArray::last()
Returns a reference to the last item in the array. The array must not be empty. If the array can be empty, check isEmpty() before calling this function.
See also first() and isEmpty().
const T & QVarLengthArray::last() const
This is an overloaded function.
int QVarLengthArray::length() const
Same as size().
See also isEmpty() and resize().
void QVarLengthArray::prepend(const T & value)
Inserts value at the beginning of the array.
This is the same as vector.insert(0, value).
For large arrays, this operation can be slow (linear time), because it requires moving all the items in the vector by one position further in memory. If you want a container class that provides a fast prepend() function, use QList or QLinkedList instead.
This function was introduced in Qt 4.8.
See also append() and insert().
void QVarLengthArray::remove(int i)
This is an overloaded function.
Removes the element at index position i.
This function was introduced in Qt 4.8.
See also insert() and replace().
void QVarLengthArray::remove(int i, int count)
This is an overloaded function.
Removes count elements from the middle of the array, starting at index position i.
This function was introduced in Qt 4.8.
See also insert() and replace().
void QVarLengthArray::removeLast()
Decreases the size of the array by one. The allocated size is not changed.
This function was introduced in Qt 4.5.
See also append().
void QVarLengthArray::replace(int i, const T & value)
Replaces the item at index position i with value.
i must be a valid index position in the array (i.e., 0 <= i < size()).
This function was introduced in Qt 4.8.
See also operator[]() and remove().
void QVarLengthArray::reserve(int size)
Attempts to allocate memory for at least size elements. If you know in advance how large the array can get, you can call this function and if you call resize() often, you are likely to get better performance. If size is an underestimate, the worst that will happen is that the QVarLengthArray will be a bit slower.
The sole purpose of this function is to provide a means of fine tuning QVarLengthArray's memory usage. In general, you will rarely ever need to call this function. If you want to change the size of the array, call resize().
See also capacity().
void QVarLengthArray::resize(int size)
Sets the size of the array to size. If size is greater than the current size, elements are added to the end. If size is less than the current size, elements are removed from the end.
If the value type is a primitive type (e.g., char, int, float) or a pointer type (e.g., QWidget *), new elements are not initialized. For other types, the elements are initialized with a default-constructed value.
See also size().
int QVarLengthArray::size() const
Returns the number of elements in the array.
See also isEmpty() and resize().
T QVarLengthArray::value(int i) const
Returns the value at index position i.
If the index i is out of bounds, the function returns a default-constructed value. If you are certain that i is within bounds, you can use at() instead, which is slightly faster.
See also at() and operator[]().
T QVarLengthArray::value(int i, const T & defaultValue) const
This is an overloaded function.
If the index i is out of bounds, the function returns defaultValue.
QVarLengthArray<T, Prealloc> & QVarLengthArray::operator+=(const T & value)
Appends value to the array and returns a reference to this vector.
This function was introduced in Qt 4.8.
See also append() and operator<<().
QVarLengthArray<T, Prealloc> & QVarLengthArray::operator<<(const T & value)
Appends value to the array and returns a reference to this vector.
This function was introduced in Qt 4.8.
See also append() and operator+=().
QVarLengthArray<T, Prealloc> & QVarLengthArray::operator=(const QVarLengthArray<T, Prealloc> & other)
Assigns other to this array and returns a reference to this array.
T & QVarLengthArray::operator[](int i)
Returns a reference to the item at index position i.
i must be a valid index position in the array (i.e., 0 <= i < size()).
See also data() and at().
const T & QVarLengthArray::operator[](int i) const
This is an overloaded function.