Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Qt's traversal iterator

Shulou Source: shulou.com Published: 2022-06-01 05:30:53 12月05日 Update

Today, I would like to share with you the relevant knowledge points about how to use Qt's ergodic iterator. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Foreword:

Qt (official pronunciation [kju:t], pronunciation with cute) is a cross-platform C++ development library, mainly used for the development of graphical user interface (Graphical User Interface,GUI) programs, of course, you can also develop command line (Command User Interface,CUI) programs without an interface.

Iterators are usually used to traverse the container, which provides a unified way to access items in the container. Qt's container class provides two types of iterators, one is a Java-style iterator and the other is an STL-style iterator. Generally speaking, C++ programmers are more accustomed to using STL-style iterators. You can also use Qt's foreach keyword if you only want to traverse items in a container sequentially.

STL style iterator:

Each container class has two STL-style iterator types, one providing read-only access and the other providing read / write access. Read-only iterators are much faster than read / write iterators, so use read-only iterators whenever possible.

Read-only iterator: "container type":: const_iterator; for example: QList::const_iterator, QMap::const_iterator.

Read / write iterator: "container type":: iterator; for example: QVector::iterator, QHash::iterator.

How to use it:

QList list;list

Tags: Iterations projects containers styles operators loops movements keys keywords functions knowledge articles types prefixes pointing methods programs clocking development two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker Shulou Tech Info NVidia Linux