tags:

views:

1036

answers:

1

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>();

see the docs here

shoosh