QStringList list; list << "apple" << "banana" << "orange"; if (list.find("banana") != -1) { qDebug() << "The word 'banana' was found in the list."; } else { qDebug() << "The word 'banana' was not found in the list."; }
QStringList list; list << "apple" << "banana" << "orange"; int index = list.find("banana"); if (index != -1) { list.replace(index, "grapefruit"); qDebug() << "The word 'banana' was found and replaced with 'grapefruit'"; } else { qDebug() << "The word 'banana' was not found in the list."; }This example is similar to the first one, but it also demonstrates how to modify the contents of the list using the replace function. If "banana" is found in the list, it will be replaced with "grapefruit", and the program will output a message saying so. If it is not found, the program will output a different message. The QStringList class is part of the QtCore library in the Qt framework.