Search code examples
c++castingconst-castqvectorqdatastream

convert from 'const QVector<QVector<qreal>>' to 'QVector<QVector<qreal>>'


How can I solve the following, ie, converting const QVector<QVector<qreal>> to QVector<QVector<qreal>>?

I tried a few steps but didn't help:

QVector<QVector<qreal>> points = const_cast<QVector<QVector<qreal>>>(abc.points);

abc.points is a struct element of type QVector<QVector<qreal>>, which I'm trying to extract from a QDataStream:

QDataStream& operator >> (QDataStream& in, const CustomPointCloud& abc)
{
    quint32 pointsCount = quint32(abc.pointsCount);
    QVector<QVector<qreal>> points =
        const_cast<QVector<QVector<qreal>>>(abc.points);
    in >> pointsCount >> points;
    return in;
}

Solution

  • Got it done by QVector<QVector<qreal>> points(abc.points);

    Please suggest if there are other approaches.