PDA

View Full Version : typedefs and Q_REGISTER_METATYPE



hickscorp
13th September 2011, 17:42
Hello,

i'm working on a large project and 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.

My question is, how can i register metatypes based on the same underlying type as different types? What would be the trick if any?

Thanks,
Pierre.

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;
}
/* ... */

hickscorp
13th September 2011, 21:32
For those interested, i have found a good solution to this problem. It will be soon online because i have posted it to qt-interest mailing list.