Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 QTreeWidgetItem 中有一个 QVariant 对象,如何将其转换为我自己的对象?
您需要在.h文件中的某处声明以下内容:
.h
Q_DECLARE_METATYPE(MyStruct)
然后你可以使用:
MyStruct s; QVariant var; var.setValue(s); // copy s into the variant // retrieve the value MyStruct s2 = var.value<MyStruct>();
在这里查看文档