In Qt, how can I convert a typed collection of objects such as a QList<T>
into a QList<QVariant>
? I suppose I could construct a new list and copy the elements over, converting each to a QVariant
along the way, but is there a shortcut?
views:
61answers:
1
+3
A:
Thanks to the Qt IRC chat room. It was staring me right in the face.
QList<MyClass> source = ...;
QVariant variant = QVariant::fromValue(source);
The variant here is a QList<QVariant>
.
Rob H
2010-02-13 04:24:07
In Qt 4.6 MinGW the QVariant contains a `QList<MyClass>`. I believe that only when you call `value<QList<QVariant> >` it will do a conversion.
rpg
2010-02-15 10:36:22