QStandardItem* item = new QStandardItem("Apple"); item->setData(10, Qt::UserRole); // Set user data to 10
QStandardItem* parentItem = new QStandardItem("Fruits"); QStandardItem* appleItem = new QStandardItem("Apple"); QStandardItem* bananaItem = new QStandardItem("Banana"); parentItem->appendRow(appleItem); parentItem->appendRow(bananaItem);This code creates a QStandardItem with the text "Fruits" and adds child items "Apple" and "Banana" to it using the appendRow() function. Package library: Qt (QtCore module)