简体   繁体   English

将T的集合转换为Qt中的QVariant的集合

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM