#include#include #include int main() { QList list = {"apple", "banana", "cherry", "apple"}; int index = list.indexOf("apple"); qDebug() << "Index of apple: " << index; // Output: Index of apple: 0 return 0; }
#includeIn this example, a list of integers is created and the indexOf method is used to find the index of the value 5, which is not in the list. The output shows that the method returns -1 to indicate that the value was not found. These examples use the Qt library, specifically the QtCore module, which provides the QList class.#include int main() { QList list = {1, 2, 3, 4}; int index = list.indexOf(5); qDebug() << "Index of 5: " << index; // Output: Index of 5: -1 return 0; }