当前位置:网站首页>QT STL type iterator
QT STL type iterator
2022-06-29 06:55:00 【Mr.codeee】
1. brief introduction
STL Iterator and Qt and STL Compatible with native algorithms , And the speed is optimized ; For every container class , There are two STL Type iterators : One for read-only access , One for read-write access . It is recommended to use a read-only iterator when there is no need to modify the data , Because it's faster .
The following table is a summary of types :
| Container class | Read only iterator | Read write iterator |
|---|---|---|
| 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 |
The difference between defining read-only iterators and read-write iterators , They use different key words ,const_iterator Define a read-only iterator ,iterator Define read-write iterators .
Besides , You can also use const_reverse_iterator and reverse_iterator Define the corresponding inverse iterator .

STL An iterator of type is a pointer to an array , therefore “++” Operator causes the iterator to point to the next data item , Operator returns the contents of the data item .STL Iterators point directly to data items .
- begin() Point to the first data item of the container
- end() Is an invalid data item , End of the said
2. Example
Use QList Read only iterators traverse the output data .
QList<QString> list;
list << "1" << "2" << "3" << "4";
QList<QString>::const_iterator i;
for (i = list.constBegin(); i != list.constEnd(); ++i)
qDebug() << *i;Use QMap Read only iterators traverse the output data .
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 ();边栏推荐
- Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future
- RPC和RMI
- Flutter is configured with a domestic image and connected to the real machine
- UVM验证平台
- Linux Installation redis
- Where is the Gcov symbol- Where are the gcov symbols?
- idea使用
- National Defense University project summary
- Fault: ntfrs warning log for id13562
- Aging design guide for applets
猜你喜欢
随机推荐
UVM authentication platform
Delete tag
How does schedulerx help users solve distributed task scheduling problems?
Fault: display Storport driver out of date in component health
Two methods for preorder traversal of binary tree
融入STEAM教育的劳动技能课程
Print Yanghui triangle
Qt 自定义位操作类
Output of character pointer to string in C language
Fault: ntfrs warning log for id13562
Small program large screen adaptation Guide
mongostat性能分析
As a qualified network worker, you must master DHCP snooping knowledge!
Qt QFileInfo简介
VerilogA - dynamic comparator
Fault: NetBt log for id4321
Browser local storage
Draw smooth curves - methods needed - drawing smooth curves - methods needed
Go basic data type conversion
The echares map is implemented separately by provinces, and the tooltip user-defined prompt box, scattered annotation and scattered illumination are explained in detail









