I just tested this for my own needs and it works in Qt 5.1.
I'm pretty new to C++ so in this line:
foreach(const QModelIndex &index, list){
I don't know if the const
and the dereferencing (&
) is needed - it works with or without. I cobbled this together from various examples I've seen.
Perhaps someone who understands C++ better can comment.
void MainWindow::on_keywordsList_clicked(const QModelIndex &index)
{
QModelIndexList list =keywordListView->selectionModel()->selectedIndexes();
QStringList slist;
foreach(const QModelIndex &index, list){
slist.append( index.data(Qt::DisplayRole ).toString());
}
qDebug() << slist.join(",");
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…