Try using this:
The QListWidget destroys your array of QListWidgetItems during the clear (so the first time it's not a problem the second time is). this code generates new items when they are needed
qDebug("inside updatelist");
quint8 qIndex;
ui->listWidget->setWrapping(false);
// ui->listWidget->clear();
qDebug()<<"total items = "<<tot_items;
for (qIndex = 0; qIndex < tot_items; ++qIndex)
{
qDebug("inside for loop");
QString item_val
= QString(ItemsInList
[qIndex
].
name).
append("\n").
append(QString("$").
append(ItemsInList
[qIndex
].
price));
qDebug()<<"list widget string to be populated = "<<item_val;
item.setText(item_val);
item.
setIcon(QIcon(icon
));
ui->listWidget->addItem(item);
}
ui->listWidget->setFocus();
qDebug("inside updatelist");
quint8 qIndex;
ui->listWidget->setWrapping(false);
// ui->listWidget->clear();
qDebug()<<"total items = "<<tot_items;
for (qIndex = 0; qIndex < tot_items; ++qIndex)
{
qDebug("inside for loop");
QString item_val = QString(ItemsInList[qIndex].name).append("\n").append(QString("$").append(ItemsInList[qIndex].price));
qDebug()<<"list widget string to be populated = "<<item_val;
QListWidgetItem * item = new QListWidgetItem;
item.setText(item_val);
QString icon = QString("/home/charvi123/QtSDK/Projects/scanIt/numbers/") + QString("%1").arg((qIndex + 1), 0, 10) + QString(".png");
item.setIcon(QIcon(icon));
ui->listWidget->addItem(item);
}
ui->listWidget->setFocus();
To copy to clipboard, switch view to plain text mode
Question why do you want to save the data twice? once in the item array and once in the listwidget
For this i would use the QStandardItemModel in combination with the QListView
Bookmarks