#include#include int main() { QStringList list = {"apple", "banana", "cherry"}; QString first = list.takeFirst(); qDebug() << first; // prints "apple" qDebug() << list; // prints "QStringList(banana, cherry)" return 0; }
#includeIn this example, we check if the list is not empty before calling takeFirst(). If the list is not empty, we remove the first element and print out a message indicating which element was removed. Package library: Qt library#include int main() { QStringList list = {"cat", "dog", "fish"}; if (!list.isEmpty()) { std::cout << list.takeFirst().toStdString() << " was removed." << std::endl; } return 0; }