QStringList myList; if (myList.empty()) { qDebug() << "The list is empty"; }
QStringList myList = {"apple", "banana", "cherry"}; if (!myList.empty()) { for (const QString& fruit : myList) { qDebug() << "I like" << fruit; } }In this example, the empty() function is used to check whether myList is not empty. If it is not empty, a for loop is used to iterate over each element in the list and print a message to the console. Package library: Qt.