QVector<T>
provides dynamic array template class. It provides better performance in most cases than QList<T>
so it should be first choice.
It can be initialized in various ways:
QVector<int> vect;
vect << 1 << 2 << 3;
QVector<int> v {1, 2, 3, 4};
The latest involves initialization list.
QVector<QString> stringsVector;
stringsVector.append("First");
stringsVector.append("Second");
You can get i-th element of vector this way:
v[i]
or at[i]
Make sure that i
is valid position, even at(i)
doesn't make a check, this is a difference from std::vector
.