QStandardItem *item = new QStandardItem; item->setText("Hello World!");
#includeIn this example, we first create a QListWidget and a QStringList containing the strings we want to add to the list. We then use a foreach loop to create a new QStandardItem for each string and set its text using setText(). Finally, we add each item to the QListWidget using addItem(). Package library: Qt5Widgets.int main(int argc, char *argv[]) { QApplication app(argc, argv); QListWidget *listWidget = new QListWidget(); QStringList stringList = { "Item 1", "Item 2", "Item 3" }; foreach(QString string, stringList) { QStandardItem *item = new QStandardItem; item->setText(string); listWidget->addItem(item); } listWidget->show(); return app.exec(); }