This is the code that worked for me thanks to the reply from Spirit.
The displayed text in the list widget is the one passed via QString description, while the 'internal' representation of the data is the one passed via unsigned int id. The 'internal' representation is stored via setData using the UserRole and is later on retrieved via the data function.
void FilterDialog
::addIdentifer(QString description,
unsigned int id
) { item->setData(Qt::UserRole, id);
listA->addItem(item);
}
QList<unsigned int> FilterDialog::getIdentifiers() {
QList<unsigned int> tmp;
for (int i=0; i<listA->count(); i++) {
tmp.append( listA->item(i)->data(Qt::UserRole).toUInt() );
}
return tmp;
}
void FilterDialog::addIdentifer(QString description, unsigned int id) {
QListWidgetItem *item = new QListWidgetItem(description, listA);
item->setData(Qt::UserRole, id);
listA->addItem(item);
}
QList<unsigned int> FilterDialog::getIdentifiers() {
QList<unsigned int> tmp;
for (int i=0; i<listA->count(); i++) {
tmp.append( listA->item(i)->data(Qt::UserRole).toUInt() );
}
return tmp;
}
To copy to clipboard, switch view to plain text mode
Bookmarks