I have a QVariant object within a QTreeWidgetItem, how can I cast it to my own object?
+6
A:
you need to declare somewhere in an .h
file the following:
Q_DECLARE_METATYPE(MyStruct)
and then you can just use:
MyStruct s;
QVariant var;
var.setValue(s); // copy s into the variant
// retrieve the value
MyStruct s2 = var.value<MyStruct>();
shoosh
2008-12-09 18:18:45