Details
-
Suggestion
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.2.2
-
None
Description
It would be nice if using QVariant with pointers were made easier, for instance, by somehow eliminating the need to cast to and from void *.
Example usage case:
This comes up, for example, when populating a combo box and attaching an object to each item. If we want to attach a Foo* type of object to a combo box entry we do:
cb->addItem( QString(str.c_str()), QVariant::fromValue((void*)obj) );
where cb is the combo box, obj is the Foo object and str is a std::string representation of that object.
Once the user has selected an item we get the associated Foo object back
with:
int idx = cb->currentIndex();
// [...] check that idx != -1
const QVariant& data = cb->itemData( idx );
const Foo* obj = static_cast<Foo*>( data.value<void*>() );
This would be typesafe if we did not have to cast to/from void*.