简体   繁体   English

如何将自定义对象转换为QVariant

[英]How to convert custom object to QVariant

I have a class called Segment which contains a few QStrings and is meant to be subclassed. 我有一个名为Segment的类,它包含一些QStrings并且是要子类化的。

I created a std::list of Segment objects and would like to convert that list into a QVariantList. 我创建了一个std::list Segment对象std::list ,并希望将该列表转换为QVariantList。 But this begins with converting my individual Segment objects into QVariant objects, how can I accomplish this? 但这首先是将我的各个Segment对象转换为QVariant对象,我该如何实现呢?

我想你正在寻找Q_DECLARE_METATYPE(Segment);.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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