我在 QTreeWidgetItem 中有一个 QVariant 对象,如何将其转换为我自己的对象?
最佳答案
您需要在 .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>();
关于c++ - 如何将 QVariant 转换为自定义类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/353694/