#includeint main() { QStringList fruits = {"Apple", "Banana", "Cherry", "Date", "Elderberry"}; QString cherry = fruits.takeAt(2); qDebug() << "Removed item:" << cherry << "\nNew list:" << fruits << endl; return 0; }
Removed item: "Cherry" New list: ("Apple", "Banana", "Date", "Elderberry")
#includeint main() { QStringList colors = {"Red", "Blue", "Green", "Yellow", "Pink"}; while(!colors.isEmpty()) { QString color = colors.takeAt(0); qDebug() << color << "removed from the list." << endl; } return 0; }
Red removed from the list. Blue removed from the list. Green removed from the list. Yellow removed from the list. Pink removed from the list.This code initializes a QStringList 'colors' and removes elements from it in a loop using 'takeAt()' method until the list becomes empty. It then prints the removed item in each iteration using qDebug() function. To use QStringList class and its methods, we need to include 'QtCore' package and header file 'QStringList' in the source file.