The model available QListView::model()contains the elements. You can do something like this:
QListView* view ;
QAbstractItemModel* model = view->model() ;
QStringList strings ;
for ( int i = 0 ; i < model->rowCount() ; ++i )
{
strings << model->index( i, 0 ).data( Qt::DisplayRole ).toString() ;
}
You also note that you want to get updated lines when writing text - you can do this by connecting the model signal dataChanged()to your function, which extracts the lines. See QAbstractItemModel::dataChanged().
source
share