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??
As a work-around, you could use fromStdVector:
auto qv = QVector<double>::fromStdVector(std::vector<double>(
vec_old.begin() + 100, vec_old.end()));
According to Qt documentation, this is not possible.
QVector Class Reference
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With