A strange problem with QList and QVector
-
Hi,
I am coming across a strange issue where my aim is to convert a
QList<double>tostd::vector<double>. This is to test a C++ code which I am trying to integrate with a Qt based GUI, altho I don't like this conversion as it it quite inefficient. Right now this is for testing purposes.Anyways:
This is the problem:
QVector<double> _temp1 =m_numerator.toVector(); QVector<double> _temp2 =m_denominator.toVector(); std::vector<double> _temp11 = _temp1.toStdVector();// No member named 'toStdVector' in List<double>' std::vector<double> _temp21 = _temp2.toStdVector();// No member named 'toStdVector' in List<double>' -
Hi,
I am coming across a strange issue where my aim is to convert a
QList<double>tostd::vector<double>. This is to test a C++ code which I am trying to integrate with a Qt based GUI, altho I don't like this conversion as it it quite inefficient. Right now this is for testing purposes.Anyways:
This is the problem:
QVector<double> _temp1 =m_numerator.toVector(); QVector<double> _temp2 =m_denominator.toVector(); std::vector<double> _temp11 = _temp1.toStdVector();// No member named 'toStdVector' in List<double>' std::vector<double> _temp21 = _temp2.toStdVector();// No member named 'toStdVector' in List<double>'@HFT_developer
There's something wrong somewhere, because _tempX are QVectors not QLists !
Try to clean/rebuild your project.I tried this with no issue:
QList<double> l={1,22,-1,.5}; QVector<double> _temp1 =l.toVector(); std::vector<double> _temp11 = _temp1.toStdVector(); -
@HFT_developer
There's something wrong somewhere, because _tempX are QVectors not QLists !
Try to clean/rebuild your project.I tried this with no issue:
QList<double> l={1,22,-1,.5}; QVector<double> _temp1 =l.toVector(); std::vector<double> _temp11 = _temp1.toStdVector();This would work in Qt5 but not Qt6.
QVector and QList were unified in Qt6 and QVector is now just an alias for QList, so the message is a bit misleading but correct - there's no direct conversion to std vector.
In Qt6 you can convert it like this:
std::vector<double> _temp11 {_temp1.begin(), _temp1.end()};Btw. if you want to avoid the copy maybe you could use
std::spanon the non-Qt side of the code? It's a wrapper over external data and you can use it just like a vector, but it doesn't copy the elements. You would create it very cheaply like this:std::span<double> _temp11 {_temp1};