Qt-interest Archive, January 2007
Casting in the QMetaType system
Message 1 in thread
Hi, I have a strange problem. I have a bunch of objects that are all
simple data storage objects that all inherit the same baseclass. They work
fine in QVariant, but if I try to access the variant from a model as the
base class it will fail since the base class is not the target class.
Since there is already a way to register the stream operators could we
explore the ability to register casting operators.
Say have something like:
qRegisterMetaTypeCastOperator( int sourceId, int targetId);
Then, as long as the developer has implemented:
operator <targetType>( const <sourceType> &source);
Then the QVariant can cast it properly. This would make it much easier to
deal with custom variants from inside of complex models.
I think the big rub is how does QVariant know that the target's type
inherits the source type. Not sure how that might work, since internally
everything is a void*.
Ideas?
-ian reinhart geiser
--
[ signature omitted ]