介绍
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 explan

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

被折叠的 条评论
为什么被折叠?



