当前位置:网站首页>Qt STL类型迭代器
Qt STL类型迭代器
2022-06-29 06:37:00 【Mr.codeee】
1.简介
STL迭代器与Qt和STL的原生算法兼容,并且进行了速度优化;对于每一个容器类,都有两个STL类型迭代器:一个用于只读访问,一个用于读写访问。无需修改数据时建议使用只读迭代器,因为速度更快。
下表为类型总表:
| 容器类 | 只读迭代器 | 读写迭代器 |
|---|---|---|
| QList<T>, QQueue<T> | QList<T>::const iterator | QList<T>::iterator |
| QLinkedList<T> | Q1. i nked List<1>: :const_iterator | QLinkedList<T>::iterator |
| QVector<T>, QStack<T> | QVector<T>::const_ilerator | QVector<T>::iterator |
| QSet<T> | QSet<T>::const_iterator | QSet<T>::iterator |
| QMap<Key, P> QMultiMap<Kcy, T> | QMap<Key, T>::const_iterator | QMap<Key, T>:: iterator |
| QHash<Key, T> QMultiHash<Key, T> | QHash<Key, T>: :const_iterator | QHash<Key, T>::iterator |
在定义只读迭代器和读写迭代器时的区别,它们使用了不同的关健字,const_iterator 定义只读迭代器,iterator 定义读写迭代器。
此外,还可以使用 const_reverse_iterator 和 reverse_iterator 定义相应的反反向迭代器。

STL 类型的迭代器是数组的指针,所以“++”运算符使迭代器指向下一个数据项,运算符返回数据项内容。STL 迭代器直接指向数据项。
- begin()指向容器的第一个数据项
- end()是无效的数据项,表示结束
2.示例
使用QList只读迭代器遍历输出数据。
QList<QString> list;
list << "1" << "2" << "3" << "4";
QList<QString>::const_iterator i;
for (i = list.constBegin(); i != list.constEnd(); ++i)
qDebug() << *i;使用QMap只读迭代器遍历输出数据。
QMap<int, int> map;
map[1] = 1;
map[2] = 2;
map[3] = 3;
QMap<int, int>::const_iterator i;
for (i = map.constBegin(); i != map.constEnd(); ++i)
qDebug () << i.key () << ':' << i.value ();边栏推荐
- UVM authentication platform
- mongostat性能分析
- Honeypot based on MySQL load data local INFILE
- What are the uses of static?
- What are the uses of wireless pressure collectors?
- 二叉树的迭代法前序遍历的两种方法
- JDBC | Chapter 5: closing and releasing JDBC connection resources
- 多线程工具类 CompletableFuture
- String and variable are spliced into variable name
- QT (x): packaging and deployment
猜你喜欢

How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli

分享 10 个 JS Promise 相关的面试题

MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory

mongostat性能分析

Yyds dry goods inventory meituan's two-sided experience, and finally there was a surprise?

作为一名合格的网工,你必须掌握的 DHCP Snooping 知识!

Observer mode vs publish subscribe mode

Creating a new generation of production and service tools with robot education

层次分析法

【OSPF引入直连路由时巧借静态黑洞路由做汇总】
随机推荐
MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future
2022.02.15 - SX10-31. House raiding III
Fault: ntfrs warning log for id13562
Json tobean
Single application and microservice application
二叉树的迭代法前序遍历的两种方法
Draw smooth curves - methods needed - drawing smooth curves - methods needed
C language pointer to function
What is 'EC2-Other' filter in 'Cost Explorer' dashboard mean? [closed]
力扣今日题-324. 摆动排序 II
JDBC | Chapter 6: simple use of database connection pool
Games101 Lecture 10 geometry 1 Notes
Observer mode vs publish subscribe mode
try anbox (by quqi99)
[Flink] flinksql and table programming cases
融入STEAM教育的劳动技能课程
Configuring the flutter development environment
WDCP访问不存在的路径全部跳转到首页不返回404的解决办法
Haar cascades and LBP cascades in face detection [closed] - Haar cascades vs. LBP cascades in face detection [closed]