Qt:QVector

0、说明

template <typename T> class QVector

QVector是存储同一个类型T数据的模板类,其功能是动态数组,数据在其中的存储是一系列连续的存储空间。

QList<T>, QLinkedList<T>, QVector<T>, and QVarLengthArray<T>提供了相似的接口和函数,它们通常可以交叉使用。

QVector和QVarLengthArray都可以接受C类型数组,而QList则不行,当我们用到C API时这点要特别注意。

 

1、模块和加载项

Header: #include <QVector>
qmake: QT += core
Inherited By:

QPolygonQPolygonFQStackQVulkanInfoVector, and QXmlStreamAttributes

2、构造

QVector(InputIterator first, InputIterator last) 用迭代器[first,last)的内容构造QVector
QVector(std::initializer_list<T> args) 用另一个std::initializer_list<T>中的元素构造QVector
QVector(QVector<T> other) 另一个QVector的副本
QVector(int size, T value) 构造大小为size,元素都是value的QVector
QVector(int size) 构造大小为size的QVector,值都是default-constructed value
QVector()  

 

5、静态方法

QVector<T> fromList(QList<T> list) 从QList构造QVector
QVector<T> fromStdVector(std::vector<T> vector) 从std::vector<T>构造QVector

 

6、实例方法

返回值类型

方法

说明

QVector<T> &

bool

QVector<T>

QVector<T> &

QVector<T> &

QVector<T> &

QVector<T> &

QVector<T> &

bool

T

operator=(QVector<T> other)

operator!=(QVector<T> other)

operator+(QVector<T> other)

operator+=(QVector<T> other)

operator+=(T value)

operator<<(T value)

operator<<(QVector<T> other)

operator=(std::initializer_list<T> args)

operator==(QVector<T> other)

operator[](int i)

赋值

两个QVector是否相等

在QVector后加另一个QVector构成新的

在QVector后加另一个QVector构成新的

在QVector后加单个Value构成新的

在QVector后加单个Value构成新的

在QVector后加另一个QVector构成新的

用std::initializer_list<T>中的元素构造

可以用v[i]访问索引i的元素

void

append(T value)

append(QVector<T> value)

在QVector后加另一个QVector构成新的

在QVector后加单个Value构成新的

T at(int i) 访问索引i的元素
QVector::const_iterator

begin()

end()

erase(QVector::iterator pos)

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

insert(QVector::iterator before, int count, T value)

insert(QVector::iterator before, T value)

cbegin()

cend()

constBegin()

constEnd()

迭代器
QVector::const_reverse_iterator

crbegin()

crend()

rbegin()

rend()

逆向迭代器
 int capacity() 该capacity的最大容量(并非实际)
void  clear() 移除所有元素并释放所有容量

const T *

T *

constData()

data()

把QVector转化为const T * 和 T *,即数组
 T

constFirst()

constLast()

第一个元素和最后一个元素
 bool contains(T value) 是否包含元素value
 int

count(T value)

count()

统计元素value的个数

统计元素数

bool

 empty()

是否为空
 bool endsWith(T value 是否以value结尾
 QVector<T> &  fill(T value, int size = -1) 用value填充剩余空间

 first()

front()

第一个元素
 int

 indexOf(T value, int from = 0)

lastIndexOf(T value, int from = -1)

第一次出现元素value的位置,顺序和倒序
void

 insert(int i, T value)

insert(int i, int count, T value)

往指定位置插入元素

往指定位置插入多个元素

 bool isEmpty()  是否为空
 T last()  最后一个元素
 int length()  元素个数,等同于size()和count()
 QVector<T>  mid(int pos, int length = -1) 中间若干个元素构成的QVector
void   move(int from, int to) 把from处的元素移动到to处
void 

pop_back()

pop_front()

push_back(T value)

push_front(T value)

移除最后一个元素

移除第一个元素

在末尾插入元素

在开头插入元素

 void  prepend(T value) 在开头插入元素
 void

remove(int i)

remove(int i, int count)

移除指定位置的元素

移除指定位置指定数量的元素

 int  removeAll(T t) 移除所有元素t
void   removeAt(int i) 等同于remove(int i)
void   removeFirst() 移除第一个元素
 void  removeLast() 移除最后一个元素
 bool removeOne(T t 移除第一个元素t
void   replace(int i, T value) 替换索引i处的元素为value
void   reserve(int size) 预留size容量
void   resize(int size) 重设QVector的大小
 void  size() 元素数
 void

shrink_to_fit()

squeeze() 

释放所有多余的控件
bool   startsWith(T value) 是否以指定元素开始
 void  swap(QVector<T> &other) 互换两个QVector的元素
 void  swapItemsAt(int i, int j) 交换QVector位置i和j处的元素
 T

 takeAt(int i)

takeFirst()

takeLast()

提取并移除指定位置的元素
QList<T>  toList()  将QVector转换为List
std::vector<T>  toStdVector()  将QVector转换为StdVector
 T

 value(int i)

value(int i, T defaultValue)

返回位置i处的元素

如果不存在,可以指定默认返回值

和at()、operator[]功能类似

 

 

posted @ 2021-07-13 15:07  ShineLe  阅读(1958)  评论(0)    收藏  举报