[Qt-interest] typedef on the same underlying type and Q_REGISTER_METATYPE
Thiago Macieira
thiago at kde.org
Tue Sep 13 19:58:43 CEST 2011
On Tuesday, 13 de September de 2011 19.25.18, MARTIN Pierre wrote:
> Hello List,
>
> 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.
> 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.
> The goal is to provide different edition widgets, like that, in my editors
> factory: /* ... */
> else if (t==qMetaTypeId<Ratio>() || t==qMetaTypeId<PositiveRatio>() ||
> t==qMetaTypeId<NegativeRatio>()) { QDoubleSpinBox *spnBx = new
> QDoubleSpinBox(p);
> spnBx->setRange(t==qMetaTypeId<PositiveRatio>() ? 0.0 : -1.0,
> t==qMetaTypeId<NegativeRatio>() ? 0.0 : 1.0); spnBx->setSingleStep (.05);
> return spnBx;
> }
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...
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110913/3704f175/attachment.bin
More information about the Qt-interest-old
mailing list