#includeint main() { QList list {1, 2, 3, 4, 5}; QList ::const_iterator it = list.constBegin(); for (; it != list.constEnd(); ++it) { std::cout << *it << " "; } return 0; }
#includeIn this example, we create a QList of QString objects and initialize it with 5 fruits. Then we use the constBegin function to get a const iterator to the beginning of the list. Finally, we iterate through the list using the const iterator and print the elements as strings to the console. Package Library: Qt Library.#include int main() { QList list {"apple", "banana", "orange", "grape", "kiwi"}; QList ::const_iterator it = list.constBegin(); for (; it != list.constEnd(); ++it) { std::cout << it->toStdString() << " "; } return 0; }