QVariant to std::vector
-
Is it possible to convert from a QVariant to a std::vector? Basically I wrapped a MyStruct up in a QVariant, this went all good, but MyStruct holds a vector of MyStruct2s. So in my QTableModel, i'm trying to access that vector via the overridden data() function, but I am not sure how to get it back into the vector state.
-
QVariant can contains std::vector, you just need to do somewhere
Q_DECLARE_METATYPE(std::vector);
Then you can use QVariant::fromValuestd::vector(v); and variant.valuestd::vector();
But you may want to convert to QVector before with QVector::from/toStdVector(). This really depends of your use case.