#include#include int main() { QStringList fruits = {"Apple", "Banana", "Cherry", "Durian"}; // iterate through list using constBegin() and constEnd() for (QStringList::const_iterator it = fruits.constBegin(); it != fruits.constEnd(); ++it) { qDebug() << *it; } return 0; }
#includeThis example demonstrates how to use constBegin() to access the first element of a QStringList. The dereferenced const_iterator object is assigned to a QString variable. The function qDebug() is used to output the value of the variable. Package library: Qt library.#include int main() { QStringList fruits = {"Apple", "Banana", "Cherry", "Durian"}; // get first element using constBegin() QString firstFruit = *fruits.constBegin(); qDebug() << "The first fruit is: " << firstFruit; return 0; }