#include#include int main() { QStringList fruits {"apple", "banana", "orange"}; // Iterate through the list and print each element for (auto it = fruits.constBegin(); it != fruits.constEnd(); ++it) { qDebug() << *it; } return 0; }
"apple" "banana" "orange"
#includeThis code creates a QStringList containing three numbers, then uses indexOf() to find the index of the last element in the list. Since constEnd() points to the end of the list, dereferencing it and subtracting 1 gives a pointer to the last element. The output will be the index of the last element, which in this case is 2. The package library for QStringList constEnd is Qt Core.int main() { QStringList numbers {"1", "2", "3"}; // Find the index of the last element int last = numbers.indexOf(*numbers.constEnd() - 1); return 0; }