I found multiple answers on how to do it from C++, but not from QML.
How is it possible to get a specific (based on index) row from QStringListModel? I tried expressions that worked from other models, but it did not work for QStringListModel. I also tried to use
var dataRow = myModel.data(rowNumber)
But it returned "undefined".
When you call
myModel.datayou are callingQVariant QAbstractItemModel::data(const QModelIndex &index, int role = Qt::DisplayRole). This methods takes aQModelIndexand an optional int for the role.The display role is what you want when you query a
QStringListModelso you don't need to specify the role parameter.However you do need to specify the index parameter with a valid
QModelIndex. You can get one from the model withQModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) constSo in your case the correct way to do it would be :
var dataRow = myModel.data(myModel.index(rowNumber, 0));You can call
dataandindexfrom QML because both areQ_INVOKABLE.