QList和QVector使用

本文介绍了QList和QVector两种Qt中的动态数组容器,它们提供了相似的API和功能,但性能有所不同。QVector通常是更好的选择,因为它在内存中顺序存储元素,而QList在某些情况下会在堆上分配元素。QList广泛用于Qt API中,适合与之交互。QLinkedList则适用于需要常量时间中间插入和使用迭代器的情况。文章提供了QList的简单范例和使用操作,包括插入、交换、查找等。
摘要由CSDN通过智能技术生成
 

介绍

QVector

The QVector class is a template class that provides a dynamic array.

QVector<T> is one of Qt’s generic container classes. It stores its items in adjacent memory locations and provides fast index-based access.

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

QVector should be your default first choice. QVector<T> will usually give better performance than QList<T>, because QVector<T> always stores its items sequentially in memory, where QList<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 Pros and Cons of Using QList for an explana

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值