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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.