PDA

View Full Version : how can iterate foreach item in QListWidget



umen
7th April 2011, 09:52
i just can find any example in the internet how to loop and get each item in the QListWidget. i need something like this : ( this is not working example ) :


QListWidget* wl = ui.listWidget_selected;
for (QWidget* w = wl.first(); w != 0; w = wl.next()) {
{
QListWidgetItem* item = ((QListWidgetItem*)w);
QString itemData = item->data(Qt::UserRole).toString();
}


again this is not working

Zlatomir
7th April 2011, 10:59
QListWidget is not a list in a container way, it's a simple list view.

Take a look at the QListWidget (http://doc.qt.nokia.com/latest/qlistwidget.html#details) documentation and you can find there how to access the items within QListWidget.

jwjoshua
8th April 2011, 07:55
Hi, this works:


for (int i = 0; i < ui->listWidget->count(); i++) {
QString itemData = ui->listWidget->item(i)->text();
}