#include#include int main() { QList list; list << "apple" << "banana" << "orange"; QString first = list.takeFirst(); qDebug() << "First element taken: " << first; qDebug() << "List after takeFirst(): " << list; return 0; } // Output: // First element taken: "apple" // List after takeFirst(): ("banana", "orange")
#includeIn this example, a QList of integers is initialized with five elements. The while loop continues until the list is empty, using takeFirst() to remove and output each element. The QList class belongs to the Qt Core module.#include int main() { QList list {1, 2, 3, 4, 5}; while (!list.isEmpty()) { int first = list.takeFirst(); qDebug() << first; } return 0; } // Output: // 1 // 2 // 3 // 4 // 5