c++qtqvector

Using a subset of a QVector in a function


How to send a portion of a QVector to a function?

QVector<int> a;
a.append(1);
a.append(2);
a.append(3);
a.append(4);
a.append(5);

Some printing function should print "2 3 4" taking the subset of the vector as an argument.

In R this would be possible using a[2:4].

Is this at all possible?

Note: In the std::vector, it is advised to use the insert function to create a new variable. This is a different insert though than QVector has, and thus I cannot find a recommended method.


Solution

  • Use the mid method:

    a.mid(1,3);