IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QVector Class

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QVector Class▲

  • Header: QVector

  • qmake: QT += core

  • Inherited By: https://

  • Group: QVector is part of tools, https://

Detailed Description▲

https://<T> is one of Qt's generic https://. It stores its items in adjacent memory locations and provides fast index-based access.

https://<T>, https://<T>, https://<T>, and https://<T> provide similar APIs and functionality. They are often interchangeable, but there are performance consequences. Here is an overview of use cases:

  • https:// should be your default first choice. https://<T> will usually give better performance than https://<T>, because https://<T> always stores its items sequentially in memory, where https://<T> will allocate its items on the heap unless sizeof(T) <= sizeof(void*) and T has been declared to be either a Q_MOVABLE_TYPE or a Q_PRIMITIVE_TYPE using Q_DECLARE_TYPEINFO. See the http:// for an explanation.

  • However, https:// is used throughout the Qt APIs for passing parameters and for returning values. Use https:// to interface with those APIs.

  • If you need a real linked list, which guarantees https:// insertions mid-list and uses iterators to items rather than indexes, use https://.

https:// and https:// both guarantee C-compatible array layout. https:// does not. This might be important if your application must interface with a C API.

Iterators into a https:// and references into heap-allocating QLists remain valid as long as the referenced items remain in the container. This is not true for iterators and references into a https:// and non-heap-allocating QLists.

Here's an example of a https:// that stores integers and a https:// that stores QString values:

 
Sélectionnez
QVector&lt;int&gt; integerVector;
QVector&lt;QString&gt; stringVector;

https:// stores its items in a vector (array). Typically, vectors are created with an initial size. For example, the following code constructs a https:// with 200 elements:

 
Sélectionnez
QVector&lt;QString&gt; vector(200);

The elements are automatically initialized with a https://. If you want to initialize the vector with a different value, pass that value as the second argument to the constructor:

 
Sélectionnez
QVector&lt;QString&gt; vector(200, "Pass");

You can also call https://() at any time to fill the vector with a value.

https:// uses 0-based indexes, just like C++ arrays. To access the item at a particular index position, you can use operator[](). On non-const vectors, operator[]() returns a reference to the item that can be used on the left side of an assignment:

 
Sélectionnez
if (vector[0] == "Liz")
    vector[0] = "Elizabeth";

For read-only access, an alternative syntax is to use https://():

 
Sélectionnez
for (int i = 0; i &lt; vector.size(); ++i) {
    if (vector.at(i) == "Alfonso")
        cout &lt;&lt; "Found Alfonso at position " &lt;&lt; i &lt;&lt; endl;
}

https://() can be faster than operator[](), because it never causes a https:// to occur.

Another way to access the data stored in a https:// is to call https://(). The function returns a pointer to the first item in the vector. You can use the pointer to directly access and modify the elements stored in the vector. The pointer is also useful if you need to pass a https:// to a function that accepts a plain C++ array.

If you want to find all occurrences of a particular value in a vector, use https://() or https://(). The former searches forward starting from a given index position, the latter searches backward. Both return the index of the matching item if they found one; otherwise, they return -1. For example:

 
Sélectionnez
int i = vector.indexOf("Harumi");
if (i != -1)
    cout &lt;&lt; "First occurrence of Harumi is at position " &lt;&lt; i &lt;&lt; endl;

If you simply want to check whether a vector contains a particular value, use https://(). If you want to find out how many times a particular value occurs in the vector, use https://().

https:// provides these basic functions to add, move, and remove items: https://(), https://(), https://(), https://(), https://(). With the exception of https://() and https://(), these functions can be slow (https://) for large vectors, because they require moving many items in the vector by one position in memory. If you want a container class that provides fast insertion/removal in the middle, use https:// or https:// instead.

Unlike plain C++ arrays, QVectors can be resized at any time by calling https://(). If the new size is larger than the old size, https:// might need to reallocate the whole vector. https:// tries to reduce the number of reallocations by preallocating up to twice as much memory as the actual data needs.

If you know in advance approximately how many items the https:// will contain, you can call https://(), asking https:// to preallocate a certain amount of memory. You can also call https://() to find out how much memory https:// actually allocated.

Note that using non-const operators and functions can cause https:// to do a deep copy of the data. This is due to https://.

https://'s value type must be an https://. This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *. A few functions have additional requirements; for example, https://() and https://() expect the value type to support operator==(). These requirements are documented on a per-function basis.

Like the other container classes, https:// provides https:// (QVectorIterator and QMutableVectorIterator) and https:// (https:// and https://). In practice, these are rarely used, because you can use indexes into the https://.

In addition to https://, Qt also provides https://, a very low-level class with little functionality that is optimized for speed.

https:// does not support inserting, prepending, appending or replacing with references to its own values. Doing so will cause your application to abort with an error message.

More Information on Using Qt Containers▲

For a detailed discussion comparing Qt containers with each other and with STL containers, see http://.

Maximum size and out-of-memory conditions▲

The current version of https:// is limited to just under 2 GB (2^31 bytes) in size. The exact value is architecture-dependent, since it depends on the overhead required for managing the data block, but is no more than 32 bytes. The number of elements that can be stored in a https:// is that size divided by the size of each element.

In case memory allocation fails, https:// will use the https:// macro, which will throw a std::bad_alloc exception if the application is being compiled with exception support. If exceptions are disabled, then running out of memory is undefined behavior.

Note that the operating system may impose further limits on applications holding a lot of allocated memory, especially large, contiguous blocks. Such considerations, the configuration of such behavior or any mitigation are outside the scope of the Qt API.

See Also▲

See also QVectorIterator, QMutableVectorIterator, https://, https://

Member Type Documentation▲

 

QVector::ConstIterator▲

Qt-style synonym for https://.

QVector::Iterator▲

Qt-style synonym for https://.

QVector::const_iterator▲

The QVector::const_iterator typedef provides an STL-style const iterator for https:// and https://.

https:// provides both https:// and https://. The STL-style const iterator is simply a typedef for "const T *" (pointer to const T).

Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read https://.

See Also▲

See also QVector::constBegin(), QVector::constEnd(), https://, QVectorIterator

QVector::const_pointer▲

Typedef for const T *. Provided for STL compatibility.

QVector::const_reference▲

Typedef for T &. Provided for STL compatibility.

[since 5.6] QVector::const_reverse_iterator▲

The QVector::const_reverse_iterator typedef provides an STL-style const reverse iterator for https://.

It is simply a typedef for std::reverse_iterator<const T*>.

Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read https://.

This typedef was introduced in Qt 5.6.

See Also▲

See also QVector::rbegin(), QVector::rend(), https://, https://

QVector::difference_type▲

Typedef for ptrdiff_t. Provided for STL compatibility.

QVector::iterator▲

The QVector::iterator typedef provides an STL-style non-const iterator for https:// and https://.

https:// provides both https:// and https://. The STL-style non-const iterator is simply a typedef for "T *" (pointer to T).

Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read https://.

See Also▲

See also https://(), QVector::end(), https://, QMutableVectorIterator

QVector::pointer▲

Typedef for T *. Provided for STL compatibility.

QVector::reference▲

Typedef for T &. Provided for STL compatibility.

[since 5.6] QVector::reverse_iterator▲

The QVector::reverse_iterator typedef provides an STL-style non-const reverse iterator for https://.

It is simply a typedef for std::reverse_iterator<T*>.

Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read https://.

This typedef was introduced in Qt 5.6.

See Also▲

See also QVector::rbegin(), QVector::rend(), https://, https://

QVector::size_type▲

Typedef for int. Provided for STL compatibility.

QVector::value_type▲

Typedef for T. Provided for STL compatibility.

Member Function Documentation▲

 

void QVector::prepend(T &&value)▲

void QVector::prepend(const T &value)

Inserts value at the beginning of the vector.

Example:

 
Sélectionnez
QVector&lt;QString&gt; vector;
vector.prepend("one");
vector.prepend("two");
vector.prepend("three");
// vector: ["three", "two", "one"]

This is the same as vector.insert(0, value).

For large vectors, this operation can be slow (https://), 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 https://() function, use https:// or https:// instead.

See Also▲

See also https://(), https://()

void QVector::insert(int i, T &&value)▲

void QVector::insert(int i, const T &value)

Inserts value at index position i in the vector. If i is 0, the value is prepended to the vector. If i is https://(), the value is appended to the vector.

Example:

 
Sélectionnez
QVector&lt;QString&gt; vector;
vector &lt;&lt; "alpha" &lt;&lt; "beta" &lt;&lt; "delta";
vector.insert(2, "gamma");
// vector: ["alpha", "beta", "gamma", "delta"]

For large vectors, this operation can be slow (https://), 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 https://() function, use https:// instead.

See Also▲

See also https://(), https://(), https://()

QVector::iterator QVector::insert(QVector::iterator before, T &&value)▲

QVector::iterator QVector::insert(QVector::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.

void QVector::push_front(T &&value)▲

void QVector::push_front(const T &value)

This function is provided for STL compatibility. It is equivalent to prepend(value).

QVector::QVector()▲

Constructs an empty vector.

See Also▲

See also https://()

QVector::QVector(int size, const T &value)▲

Constructs a vector with an initial size of size elements. Each element is initialized with value.

See Also▲

See also https://(), https://()

QVector::QVector(const QVector<T> &other)▲

Constructs a copy of other.

This operation takes https://, because https:// is https://. This makes returning a https:// from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes https://.

See Also▲

See also https://()

[since 5.2] QVector::QVector(QVector<T> &&other)▲

Move-constructs a https:// instance, making it point at the same object that other was pointing to.

This function was introduced in Qt 5.2.

[default] QVector::QVector(int size)▲

Constructs a vector with an initial size of size elements.

The elements are initialized with a https://.

See Also▲

See also https://()

[default, since 4.8] QVector::QVector(std::initializer_list<T> args)▲

Constructs a vector from the std::initializer_list given by args.

This constructor is only enabled if the compiler supports C++11 initializer lists.

This function was introduced in Qt 4.8.

QVector::~QVector()▲

Destroys the vector.

void QVector::append(const T &value)▲

Inserts value at the end of the vector.

Example:

 
Sélectionnez
QVector&lt;QString&gt; vector;
vector.append("one");
vector.append("two");
QString three = "three";
vector.append(three);
// vector: ["one", "two", "three"]
// three: "three"

This is the same as calling resize(https://() + 1) and assigning value to the new last element in the vector.

This operation is relatively fast, because https:// typically allocates more memory than necessary, so it can grow without reallocating the entire vector each time.

See Also▲

See also https://(), https://(), https://()

[since 5.6] void QVector::append(T &&value)▲

This is an overloaded function.

Example:

 
Sélectionnez
QVector&lt;QString&gt; vector;
vector.append("one");
vector.append("two");
QString three = "three";
vector.append(std::move(three));
// vector: ["one", "two", "three"]
// three: ""

This function was introduced in Qt 5.6.

[since 5.5] void QVector::append(const QVector<T> &value)▲

This is an overloaded function.

Appends the items of the value vector to this vector.

This function was introduced in Qt 5.5.

See Also▲

See also https://(), https://()

const T &QVector::at(int i) const▲

Returns the item at index position i in the vector.

i must be a valid index position in the vector (i.e., 0 <= i < https://()).

See Also▲

See also https://(), https://()

QVector::reference QVector::back()▲

This function is provided for STL compatibility. It is equivalent to https://().

QVector::const_reference QVector::back() const▲

This is an overloaded function.

QVector::iterator QVector::begin()▲

Returns an https:// pointing to the first item in the vector.

See Also▲

See also constBegin(), end()

QVector::const_iterator QVector::begin() const▲

This is an overloaded function.

int QVector::capacity() const▲

Returns the maximum number of items that can be stored in the vector without forcing a reallocation.

The sole purpose of this function is to provide a means of fine tuning https://'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 vector, call https://().

See Also▲

See also https://(), https://()

void QVector::clear()▲

Removes all the elements from the vector.

Until Qt 5.6, this also released the memory used by the vector. From Qt 5.7, the capacity is preserved. To shed all capacity, swap with a default-constructed vector:

 
Sélectionnez
QVector&lt;T&gt; v ...;
QVector&lt;T&gt;().swap(v);
Q_ASSERT(v.capacity() == 0);

or call https://().

See Also▲

See also https://()

const T *QVector::constData() const▲

Returns a const pointer to the data stored in the vector. The pointer can be used to access the items in the vector. The pointer remains valid as long as the vector isn't reallocated.

This function is mostly useful to pass a vector to a function that accepts a plain C++ array.

See Also▲

See also https://(), https://()

[since 5.6] const T &QVector::constFirst() const▲

Returns a const reference to the first item in the vector. This function assumes that the vector isn't empty.

This function was introduced in Qt 5.6.

See Also▲

See also https://(), https://(), https://()

[since 5.6] const T &QVector::constLast() const▲

Returns a const reference to the last item in the vector. This function assumes that the vector isn't empty.

This function was introduced in Qt 5.6.

See Also▲

See also https://(), https://(), https://()

bool QVector::contains(const T &value) const▲

Returns true if the vector contains an occurrence of value; otherwise returns false.

This function requires the value type to have an implementation of operator==().

See Also▲

See also https://(), https://()

int QVector::count(const T &value) const▲

Returns the number of occurrences of value in the vector.

This function requires the value type to have an implementation of operator==().

See Also▲

See also https://(), https://()

int QVector::count() const▲

This is an overloaded function.

Same as https://().

T *QVector::data()▲

Returns a pointer to the data stored in the vector. The pointer can be used to access and modify the items in the vector.

Example:

 
Sélectionnez
QVector&lt;int&gt; vector(10);
int *data = vector.data();
for (int i = 0; i &lt; 10; ++i)
    data[i] = 2 * i;

The pointer remains valid as long as the vector isn't reallocated.

This function is mostly useful to pass a vector to a function that accepts a plain C++ array.

See Also▲

See also https://(), https://()

const T *QVector::data() const▲

This is an overloaded function.

bool QVector::empty() const▲

This function is provided for STL compatibility. It is equivalent to https://(), returning true if the vector is empty; otherwise returns false.

[since 4.5] bool QVector::endsWith(const T &value) const▲

Returns true if this vector is not empty and its last item is equal to value; otherwise returns false.

This function was introduced in Qt 4.5.

See Also▲

See also https://(), https://()

QVector::iterator QVector::erase(QVector::iterator pos)▲

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()).

See Also▲

See also https://(), https://()

QVector::iterator QVector::erase(QVector::iterator begin, QVector::iterator end)▲

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.

QVector<T> &QVector::fill(const T &value, int size = -1)▲

Assigns value to all items in the vector. If size is different from -1 (the default), the vector is resized to size size beforehand.

Example:

 
Sélectionnez
QVector&lt;QString&gt; vector(3);
vector.fill("Yes");
// vector: ["Yes", "Yes", "Yes"]

vector.fill("oh", 5);
// vector: ["oh", "oh", "oh", "oh", "oh"]
See Also▲

See also https://()

T &QVector::first()▲

Returns a reference to the first item in the vector. This function assumes that the vector isn't empty.

See Also▲

See also https://(), https://(), https://()

const T &QVector::first() const▲

This is an overloaded function.

[static] QVector<T> QVector::fromList(const QList<T> &list)▲

Returns a https:// object with the data contained in list.

Example:

 
Sélectionnez
QStringList list;
list &lt;&lt; "Sven" &lt;&lt; "Kim" &lt;&lt; "Ola";

QVector&lt;QString&gt; vect = QVector&lt;QString&gt;::fromList(list);
// vect: ["Sven", "Kim", "Ola"]
See Also▲

See also https://(), https://()

[static] QVector<T> QVector::fromStdVector(const std::vector<T> &vector)▲

Returns a https:// object with the data contained in vector. The order of the elements in the https:// is the same as in vector.

Example:

 
Sélectionnez
std::vector&lt;double&gt; stdvector;
vector.push_back(1.2);
vector.push_back(0.5);
vector.push_back(3.14);

QVector&lt;double&gt; vector = QVector&lt;double&gt;::fromStdVector(stdvector);
See Also▲

See also https://(), https://()

T &QVector::front()▲

This function is provided for STL compatibility. It is equivalent to https://().

QVector::const_reference QVector::front() const▲

This is an overloaded function.

int QVector::indexOf(const T &value, int from = 0) const▲

Returns the index position of the first occurrence of value in the vector, searching forward from index position from. Returns -1 if no item matched.

Example:

 
Sélectionnez
QVector&lt;QString&gt; vector;
vector &lt;&lt; "A" &lt;&lt; "B" &lt;&lt; "C" &lt;&lt; "B" &lt;&lt; "A";
vector.indexOf("B");            // returns 1
vector.indexOf("B", 1);         // returns 1
vector.indexOf("B", 2);         // returns 3
vector.indexOf("X");            // returns -1

This function requires the value type to have an implementation of operator==().

See Also▲

See also https://(), https://()

void QVector::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.

Example:

 
Sélectionnez
QVector&lt;double&gt; vector;
vector &lt;&lt; 2.718 &lt;&lt; 1.442 &lt;&lt; 0.4342;
vector.insert(1, 3, 9.9);
// vector: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342]

bool QVector::isEmpty() const▲

Returns true if the vector has size 0; otherwise returns false.

See Also▲

See also https://(), https://()

T &QVector::last()▲

Returns a reference to the last item in the vector. This function assumes that the vector isn't empty.

See Also▲

See also https://(), https://(), https://()

const T &QVector::last() const▲

This is an overloaded function.

int QVector::lastIndexOf(const T &value, int from = -1) const▲

Returns the index position of the last occurrence of the value value in the vector, searching backward from index position from. If from is -1 (the default), the search starts at the last item. Returns -1 if no item matched.

Example:

 
Sélectionnez
QList&lt;QString&gt; vector;
vector &lt;&lt; "A" &lt;&lt; "B" &lt;&lt; "C" &lt;&lt; "B" &lt;&lt; "A";
vector.lastIndexOf("B");        // returns 3
vector.lastIndexOf("B", 3);     // returns 3
vector.lastIndexOf("B", 2);     // returns 1
vector.lastIndexOf("X");        // returns -1

This function requires the value type to have an implementation of operator==().

See Also▲

See also https://()

[since 5.2] int QVector::length() const▲

Same as https://() and https://().

Provided for compatibility with https://.

This function was introduced in Qt 5.2.

See Also▲

See also https://(), https://(), https://()

QVector<T> QVector::mid(int pos, int length = -1) const▲

Returns a sub-vector which contains elements from this vector, starting at position pos. If length is -1 (the default), all elements after pos are included; otherwise length elements (or all remaining elements if there are less than length elements) are included.

[since 5.6] void QVector::move(int from, int to)▲

Moves the item at index position from to index position to.

Provided for compatibility with https://.

This function was introduced in Qt 5.6.

See Also▲

See also https://()

void QVector::pop_back()▲

This function is provided for STL compatibility. It is equivalent to https://().

void QVector::pop_front()▲

This function is provided for STL compatibility. It is equivalent to https://().

void QVector::push_back(const T &value)▲

This function is provided for STL compatibility. It is equivalent to append(value).

[since 5.6] void QVector::push_back(T &&value)▲

This is an overloaded function.

This function was introduced in Qt 5.6.

void QVector::remove(int i)▲

This is an overloaded function.

Removes the element at index position i.

See Also▲

See also https://(), https://(), https://()

void QVector::remove(int i, int count)▲

This is an overloaded function.

Removes count elements from the middle of the vector, starting at index position i.

See Also▲

See also https://(), https://(), https://()

[since 5.4] int QVector::removeAll(const T &t)▲

Removes all elements that compare equal to t from the vector. Returns the number of elements removed, if any.

Provided for compatibility with https://.

This function was introduced in Qt 5.4.

See Also▲

See also https://(), https://()

[since 5.2] void QVector::removeAt(int i)▲

Removes the element at index position i. Equivalent to

 
Sélectionnez
remove(i);

Provided for compatibility with https://.

This function was introduced in Qt 5.2.

See Also▲

See also https://(), https://()

[since 5.1] void QVector::removeFirst()▲

Removes the first item in the vector. Calling this function is equivalent to calling remove(0). The vector must not be empty. If the vector can be empty, call https://() before calling this function.

This function was introduced in Qt 5.1.

See Also▲

See also https://(), https://(), https://()

[since 5.1] void QVector::removeLast()▲

Removes the last item in the vector. Calling this function is equivalent to calling remove(https://() - 1). The vector must not be empty. If the vector can be empty, call https://() before calling this function.

This function was introduced in Qt 5.1.

See Also▲

See also https://(), https://(), https://(), https://()

[since 5.4] bool QVector::removeOne(const T &t)▲

Removes the first element that compares equal to t from the vector. Returns whether an element was, in fact, removed.

Provided for compatibility with https://.

This function was introduced in Qt 5.4.

See Also▲

See also https://(), https://()

void QVector::replace(int i, const T &value)▲

Replaces the item at index position i with value.

i must be a valid index position in the vector (i.e., 0 <= i < https://()).

See Also▲

See also https://(), https://()

void QVector::reserve(int size)▲

Attempts to allocate memory for at least size elements. If you know in advance how large the vector will be, you should call this function to prevent reallocations and memory fragmentation.

If size is an underestimate, the worst that will happen is that the https:// will be a bit slower. If size is an overestimate, you may have used more memory than the normal https:// growth strategy would have allocated—or you may have used less.

An alternative to reserve() is calling https://(). Whether or not that is faster than reserve() depends on the element type, because https://() default-constructs all elements, and requires assignment to existing entries rather than calling https://(), which copy- or move-constructs. For simple types, like int or double, https://() is typically faster, but for anything more complex, you should prefer reserve().

If the size passed to https://() was underestimated, you run out of allocated space and into undefined behavior. This problem does not exist with reserve(), because it treats the size as just a hint.

See Also▲

See also https://(), https://()

void QVector::resize(int size)▲

Sets the size of the vector to size. If size is greater than the current size, elements are added to the end; the new elements are initialized with a https://. If size is less than the current size, elements are removed from the end.

Since Qt 5.6, resize() doesn't shrink the capacity anymore. To shed excess capacity, use https://().

See Also▲

See also https://()

[since 5.10] void QVector::shrink_to_fit()▲

This function is provided for STL compatibility. It is equivalent to https://().

This function was introduced in Qt 5.10.

int QVector::size() const▲

Returns the number of items in the vector.

See Also▲

See also https://(), https://()

void QVector::squeeze()▲

Releases any memory not required to store the items.

The sole purpose of this function is to provide a means of fine tuning https://'s memory usage. In general, you will rarely ever need to call this function.

See Also▲

See also https://(), https://()

[since 4.5] bool QVector::startsWith(const T &value) const▲

Returns true if this vector is not empty and its first item is equal to value; otherwise returns false.

This function was introduced in Qt 4.5.

See Also▲

See also https://(), https://()

[since 5.2] T QVector::takeAt(int i)▲

Removes the element at index position i and returns it.

Equivalent to

 
Sélectionnez
T t = at(i);
remove(i);
return t;

Provided for compatibility with https://.

This function was introduced in Qt 5.2.

See Also▲

See also https://(), https://(), https://()

[since 5.1] T QVector::takeFirst()▲

Removes the first item in the vector and returns it. This function assumes the vector is not empty. To avoid failure, call https://() before calling this function.

This function was introduced in Qt 5.1.

See Also▲

See also https://(), https://()

[since 5.1] T QVector::takeLast()▲

Removes the last item in the list and returns it. This function assumes the vector is not empty. To avoid failure, call https://() before calling this function.

If you don't use the return value, https://() is more efficient.

This function was introduced in Qt 5.1.

See Also▲

See also https://(), https://()

QList<T> QVector::toList() const▲

Returns a https:// object with the data contained in this https://.

Example:

 
Sélectionnez
QVector&lt;double&gt; vect;
vect &lt;&lt; "red" &lt;&lt; "green" &lt;&lt; "blue" &lt;&lt; "black";

QList&lt;double&gt; list = vect.toList();
// list: ["red", "green", "blue", "black"]
See Also▲

See also https://(), https://()

std::vector<T> QVector::toStdVector() const▲

Returns a std::vector object with the data contained in this https://. Example:

 
Sélectionnez
QVector&lt;double&gt; vector;
vector &lt;&lt; 1.2 &lt;&lt; 0.5 &lt;&lt; 3.14;

std::vector&lt;double&gt; stdvector = vector.toStdVector();
See Also▲

See also https://(), https://()

T QVector::value(int i) const▲

Returns the value at index position i in the vector.

If the index i is out of bounds, the function returns a https://. If you are certain that i is within bounds, you can use https://() instead, which is slightly faster.

See Also▲

See also https://(), https://()

T QVector::value(int i, const T &defaultValue) const▲

This is an overloaded function.

If the index i is out of bounds, the function returns defaultValue.

bool QVector::operator!=(const QVector<T> &other) const▲

Returns true if other is not equal to this vector; otherwise returns false.

Two vectors are considered equal if they contain the same values in the same order.

This function requires the value type to have an implementation of operator==().

See Also▲

See also https://()

QVector<T> QVector::operator+(const QVector<T> &other) const▲

Returns a vector that contains all the items in this vector followed by all the items in the other vector.

See Also▲

See also https://()

QVector<T> &QVector::operator+=(const QVector<T> &other)▲

Appends the items of the other vector to this vector and returns a reference to this vector.

See Also▲

See also https://(), https://()

QVector<T> &QVector::operator+=(const T &value)▲

This is an overloaded function.

Appends value to the vector.

See Also▲

See also https://(), https://()

[since 5.11] QVector<T> &QVector::operator+=(T &&value)▲

This is an overloaded function.

This function was introduced in Qt 5.11.

See Also▲

See also https://(), https://()

QVector<T> &QVector::operator<<(const T &value)▲

Appends value to the vector and returns a reference to this vector.

See Also▲

See also https://(), https://()

QVector<T> &QVector::operator<<(const QVector<T> &other)▲

Appends other to the vector and returns a reference to the vector.

[since 5.11] QVector<T> &QVector::operator<<(T &&value)▲

This is an overloaded function.

This function was introduced in Qt 5.11.

See Also▲

See also https://(), https://()

QVector<T> &QVector::operator=(const QVector<T> &other)▲

Assigns other to this vector and returns a reference to this vector.

[default, since 5.2] QVector<T> &QVector::operator=(QVector<T> &&other)▲

Move-assigns other to this https:// instance.

This function was introduced in Qt 5.2.

bool QVector::operator==(const QVector<T> &other) const▲

Returns true if other is equal to this vector; otherwise returns false.

Two vectors are considered equal if they contain the same values in the same order.

This function requires the value type to have an implementation of operator==().

See Also▲

See also https://()

T &QVector::operator[](int i)▲

Returns the item at index position i as a modifiable reference.

i must be a valid index position in the vector (i.e., 0 <= i < https://()).

Note that using non-const operators can cause https:// to do a deep copy.

See Also▲

See also https://(), https://()

const T &QVector::operator[](int i) const▲

This is an overloaded function.

Same as at(i).

Related Non-Members▲

 

QDataStream &operator<<(QDataStream &out, const QVector<T> &vector)▲

Writes the vector vector to stream out.

This function requires the value type to implement operator<<().

See Also▲

See also https://

QDataStream &operator>>(QDataStream &in, QVector<T> &vector)▲

Reads a vector from stream in into vector.

This function requires the value type to implement operator>>().

See Also▲

See also https://

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.