[Qt-interest] typedef on the same underlying type and Q_REGISTER_METATYPE
MARTIN Pierre
hickscorp at gmail.com
Tue Sep 13 20:10:28 CEST 2011
>> i would like to be able to do as follows:
>> typedef qreal Ratio;
>> typedef qreal PositiveRatio;
>> typedef qreal NegativeRatio;
>> Q_DECLARE_METATYPE(Ratio);
>> Q_DECLARE_METATYPE(PositiveRatio);
>> Q_DECLARE_METATYPE(NegativeRatio);
>> However, the compiler doesn't like it, and only accepts to register the
>> first one. So, how can i register metatypes based on the same underlying
>> type as different types?
> You can't. You need different types.
Hm that's what i thought. My first conclusion was to think about a lightweight wrapper class, like TypeWrapper<T> with a load of operators to allow ease of subclass.
>> What would be the trick if any? Even if the
>> underlying data type is the same, the typedefs on top of them should be
>> considered as different...
> The typedef is just an alias. The compiler forgets about them shortly
> afterwards. After the compilation pass, the typedefs are gone. Only the
> underlying types remain.
Perfect explaination. Thanks.
> You'll have to find another solution for the problem.
> You can create structs:
> struct Ratio { qreal data; };
> struct PositiveRatio { qreal data; };
> struct NegativeRatio { qreal data; };
> Q_DECLARE_TYPEINFO(Ratio, Q_MOVABLE_TYPE)
> Q_DECLARE_METATYPE(Ratio)
> Q_DECLARE_TYPEINFO...
What is exactly Q_MOVABLE_TYPE? i'm googling it, but i don't seem to find much information about it... Can you tell me a bit more about this technique please?
Thanks for your time :)
Pierre.
More information about the Qt-interest-old
mailing list