#include#include int main() { QList list; list.append("Apple"); list.append("Banana"); list.append("Cherry"); // You can also use the operator<< to add items list << "Grapes" << "Mango"; // Prints all the items in the list for (auto i = list.begin(); i != list.end(); ++i) { cout << *i << endl; } return 0; }
#includeThis example shows how to remove items from a QList using the `removeAt` function and the `erase` function. The latter function is used to remove all items that satisfy a certain condition. Package/library: Qtint main() { QList list = {1, 2, 3, 4, 5}; // Removes the item at index 2 (value 3) list.removeAt(2); // Removes all the items that are greater than or equal to 4 for (auto i = list.begin(); i != list.end();) { if (*i >= 4) { i = list.erase(i); } else { ++i; } } // Prints all the items in the list for (auto i = list.begin(); i != list.end(); ++i) { cout << *i << endl; } return 0; }