Qt 6.5 : how to convert QList to std::vector ?
-
Hello,
I am porting a Qt5 code that uses a library that manipulates std::vector objects. In Qt5, I would convert a QList to a std::vector like this :
QList<double> myL; std::vector<double> myV = myL.toVector().toStdVector()
But QList::toVector() has become obsolete, and toStdVector() has disappeared. What is the new best way to do this conversion in Qt6.5 ?
-
Hello,
I am porting a Qt5 code that uses a library that manipulates std::vector objects. In Qt5, I would convert a QList to a std::vector like this :
QList<double> myL; std::vector<double> myV = myL.toVector().toStdVector()
But QList::toVector() has become obsolete, and toStdVector() has disappeared. What is the new best way to do this conversion in Qt6.5 ?
I guess something like this should work:
std::vector<double> myV(myL.constBegin(), myL.constEnd());
-
Hello,
I am porting a Qt5 code that uses a library that manipulates std::vector objects. In Qt5, I would convert a QList to a std::vector like this :
QList<double> myL; std::vector<double> myV = myL.toVector().toStdVector()
But QList::toVector() has become obsolete, and toStdVector() has disappeared. What is the new best way to do this conversion in Qt6.5 ?
Since QList and QVector is the same, toVector() is not needed anymore. And for the construction of std::vector you can use the range constructor:
std::vector<double> v(l. constBegin(), l.constEnd());