DNamto
DNamto

Reputation: 1362

How to iterate QAbstractListModel?

I have a requirement where I have QAbstractListModel which is being updated continuously. The data type of QAbstractListModel is integar type.

I would like to copy the whole data at particular intervals into the vector so that vector is updated continuously and I can use it further.

Any idea how can I iterate QAbstractListModel by its index and copy it into vector.

Upvotes: 2

Views: 2854

Answers (1)

benjarobin
benjarobin

Reputation: 4488

Quick and dirty way of doing it :

QAbstractListModel m;
QVector<int> v;

const int nbRow = m.rowCount();
v.reserve(nbRow);

for (int i = 0; i < nbRow; ++i)
{
    int myInt = m.index(i, 0).data().toInt();
    v.append(myInt);
}

Upvotes: 5

Related Questions