0

Can't get the list to display?

enter image description here

/*create QListView */
m_listViewA = new QListView(this);
m_listViewA->setGeometry(QRect(QPoint(0,100), QSize(100, 150)));

modelA = new QStandardItemModel( nrow, 1, this );

//fill model value
for( int r=0; r<nrow; r++ )
{
    QString sstr = "[ " + QString::number(r) + " ]";
    QStandardItem *item = new QStandardItem(QString("Idx ") + sstr);
    modelA->setItem(r, 0, item);
}
//set model
m_listViewA->setModel(modelA);
m_listViewA->setSelectionMode( QAbstractItemView::ExtendedSelection );

QStringList slist;
foreach(const QStandardItem index, modelA) //ERROR
{
    slist.append( index.data(Qt::DisplayRole ).toString());
}
4

1 回答 1

0

这有效......但宁愿使用“foreach”......

QString strA;
for(int r=0; r < modelA->rowCount(); r++)
{
    strA += "\r\n" + modelA->item(r,0)->text();
}
QMessageBox *msgBox = new QMessageBox(0);
msgBox->setGeometry(QRect(QPoint(200,200),QSize(400,400)));
msgBox->setInformativeText(strA);
msgBox->exec();
于 2013-08-07T17:41:04.087 回答