numberCruncher
numberCruncher

Reputation: 645

QPersistentModelIndex from QModelIndex

If I have a QList<QPersistentModelIndex> and a function which gets a list of QModelIndex like this:

Q_INVOKABLE void storeSelection(const QModelIndexList& list) {
        _selectedIndices.clear();
        _selectedIndices.reserve(list.size());
        for(int i=0;i<list.count();i++) {
            _selectedIndices.append(QPersistentModelIndex(list[i]));
        }
    }

do I need to create do QPersistentModelIndex(list[i]) in the append or could I simply append the list[i] and it is automatically converted to a QPersistentModelIndex

Upvotes: 1

Views: 940

Answers (1)

Sergio Monteleone
Sergio Monteleone

Reputation: 2886

QPersistentModelIndex class has a constructor which takes a const QModelIndex reference (here the documentation).

Hence, there is no need to explicitly call the constructor:

_selectedIndices.append(list[i]);

and

_selectedIndices.append(QPersistentModelIndex(list[i]));

should be equivalent.

Upvotes: 3

Related Questions