Qt5 Tutorial QList - 2020
bogotobogo.com site search:
QList
In this tutorial, we will learn about QList.
The QList class is a template class that provides lists.
QList<T> is one of Qt's generic container classes. It stores a list of values and provides fast index-based access as well as fast insertions and removals.
Although it is implemented as an array-list, it provides very fast prepends and appends. For most applications, QList is the best type to use.
Index lookup | Insertion | Prepending | Appending | |
---|---|---|---|---|
QLinkedList<T> | O(n) | O(1) | O(1) | O(1) |
QList<T> | O(1) | O(n) | Amort. O(1) | Amort. O(1) |
QVector<T> | O(1) | O(n) | O(n) | Amort. O(1) |
#include <QCoreApplication> #include <QList> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QList<int> List; for(int i = 0; i < 6; i++) List.append(i); List.removeOne(4); foreach(int n, List) qDebug() << n; return a.exec(); }
Output:
0 1 2 3 5
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization