Reputation: 5290
Is it not possible to construct a new QVector object from iterators like C++ vectors??
QVector<double> new_vec(vec_old.begin()+100,vec_old.end())
I'm getting errors when I'm trying to do something like this.Also what is the best way to construct a new QVector object from a part of other QVector??
Upvotes: 3
Views: 917
Reputation: 476970
As a work-around, you could use fromStdVector
:
auto qv = QVector<double>::fromStdVector(std::vector<double>(
vec_old.begin() + 100, vec_old.end()));
Upvotes: 5
Reputation: 2239
According to Qt documentation, this is not possible.
Answering your second question, to create a QVector
from a part of other QVector
, I believe the following is one of the best options:
QVector<double> new_vec(vec_old.size-100);
double* dt = vec_old.constData;
dt += 100; // some pointer arithmetic.
new_vec.fill((*dt), vec_old.size-100);
This will only copy data starting at some specified position until the end, just like you wrote.
Upvotes: 4