#include#include int main() { QList list; list.append("apple"); list.append("banana"); list.append("orange"); // Use a const iterator to loop through the list for (auto it = list.cbegin(); it != list.cend(); ++it) { qDebug() << *it; } return 0; }
#includeIn this example, we create a QList object and use the << operator to add some integers to it. We then use cend() to get the ending iterator and decrement it to get the last element of the list. The Qt library is used to provide the QList class.#include int main() { QList list; list << 1 << 2 << 3 << 4 << 5; // Use cend() to get the ending iterator and decrement it auto it = list.cend(); --it; qDebug() << "Last element: " << *it; return 0; }