I'm trying to create a Qvector from and std::Vector.
I can of course copy it element by element using a for loop, but I'm looking for a better way to do it.
So I tried:
QVector<double> qv = QVector<double>::fromStdVector(values) ;
This works fine but I get a warning that it's deprecated.
I followed Hadi Navapour's suggestion from copying a std::vector to a qvector
and tried the following:
QVector<double> qv = QVector<double>(values.begin(), values.end());
but this code with begin() and end() does not compile, I get the following error:
error: no matching function for call to 'QVector::QVector(std::vector::iterator, std::vector::iterator)' QVector qv = QVector(values.begin(), values.end());
I believe this is supposed to use the following constructor QVector(InputIterator first, InputIterator last)
I can't get it to work.
Could someone please explain the right non-deprecated way to copy an std::vector to a Qvector?
Thanks in advance!
The documentation https://doc.qt.io/qt-5/qvector.html#fromStdVector enforces to use range constructors from version 5.14.
so may be you can use version flags for your implementation.
try as said below, if you are interested.
#if QT_VERSION <= QT_VERSION_CHECK(5,14,0)
QVector<double> qv = QVector<double>::fromStdVector(values) ;
#else
QVector<double> qv = QVector<double>(values.begin(), values.end());
#endif
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.