[英]Convert collection of T into collection of QVariant in Qt
In Qt, how can I convert a typed collection of objects such as a QList<T>
into a QList<QVariant>
? 在Qt中,如何将类型化的对象集合(例如
QList<T>
转换为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? 我想我可以构造一个新列表并复制元素,然后将它们转换为
QVariant
,但是有捷径吗?
Thanks to the Qt IRC chat room. 感谢Qt IRC聊天室。 It was staring me right in the face.
它正盯着我。
QList<MyClass> source = ...;
QVariant variant = QVariant::fromValue(source);
The variant here is a QList<QVariant>
. 这里的变体是
QList<QVariant>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.