选用QList还是选用QVector?

中才德创 2010-09-08 12:25:43
QList<ST_DEVICE_INFO> lst;
QVector<ST_DEVICE_INFO> vec;

结构体里,“整形、枚举、字符串”。
想用个表来存放,它们究竟有些什么异同点?
struct ST_DEVICE_INFO
{
int iPort;
enum enProtocol;
char *Name[MAX_DEVICE_NAME_LEN];
}
...全文
1325 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
blueliuyun 2011-08-02
  • 打赏
  • 举报
回复
QVector
QList
QLinkedList
……
tingsking18 2010-09-09
  • 打赏
  • 举报
回复
一个随即存取,一个连续存取。
gaowenboms 2010-09-09
  • 打赏
  • 举报
回复
看你的需求了,LIST是插入快,VECTOR是查找快
tzcherish 2010-09-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 rex237 的回复:]
For most purposes, QList is the right class to use. Operations like prepend() and insert() are usually faster than with QVector because of the way QList stores its items in memory (see Algorithmic Com……
[/Quote]
爱看帮助手册的娃,都是好娃。。。
aoxuehan0424 2010-09-09
  • 打赏
  • 举报
回复
首先,一个是随机存取,一个是连续存取,所以list插入删除很快,vector查询很快。
但是vector有个地方一定要注意:
vector:如果你添加元素,但是vector的容量(是容量,不是大小,容量比大小大,会预先多分配空间)不够的话,系统就会重新分配一段内存,然后把原先的内容全部拷贝过去,然后删除原先的内容。所以,如果你设定了一个纸箱vector的指针,或者说迭代器,在你添加元素之后,这个指针(迭代器)需要重新计算。
Rex237 2010-09-08
  • 打赏
  • 举报
回复
For most purposes, QList is the right class to use. Operations like prepend() and insert() are usually faster than with QVector because of the way QList stores its items in memory (see Algorithmic Complexity for details), and its index-based API is more convenient than QLinkedList's iterator-based API. It also expands to less code in your executable.

If you want the items to occupy adjacent memory positions, or if your items are larger than a pointer and you want to avoid the overhead of allocating them on the heap individually at insertion time, then use QVector.
If you want a low-level variable-size array, QVarLengthArray may be sufficient.
lefttime 2010-09-08
  • 打赏
  • 举报
回复
QList比较常用些, 再者根据官方解释, 对于按索引来查询数据相对QVector会快```具体没测试...@@
  • 打赏
  • 举报
回复
两个类使用起来差不多,但是本质一个是链表一个是数值,处理上当然还是不一样的
DIE654456 2010-09-08
  • 打赏
  • 举报
回复
The QList class is a template class that provides lists。
The QVector class is a template class that provides a dynamic array。
在Qt里这两个类使用方式差不多。

16,215

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧