QListWidgetItem *item = new QListWidgetItem("Hello, World!"); listWidget->addItem(item);
QListWidgetItem *item = new QListWidgetItem(); item->setText("Item 1"); item->setData(Qt::UserRole, 42); listWidget->addItem(item);In this example, we create a QListWidgetItem object and set its text to "Item 1". We then use the setData() method to store an integer value of 42 with the item using the Qt::UserRole key. This allows us to store arbitrary data with each item. Package library: Qt