QStringList list; list << "apple" << "banana" << "orange" << "mango"; list.erase(list.begin() + 2); // Output: [ "apple", "banana", "mango" ]
QStringList list; list << "apple" << "banana" << "orange" << "mango"; list.erase(list.begin() + 1, list.end() - 1); // Output: [ "apple", "mango" ]Description: In this example, we created a QStringList named list and added four items to it. Then we used the erase() function to remove a range of items from the list (i.e., from the second item to the second-last item). The end() function returns an iterator pointing to one past the last item of the list, and we subtracted 1 from it to point to the last item. Package Library: Qt library.