views:

61

answers:

1

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?

+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
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