Instead of your for loop you can use QListWidget::row(const QListWidgetItem * item).