[Development] QMetaTypeId and QMetaTypeId2

Olivier Goffart olivier at woboq.com
Thu Feb 9 13:34:57 CET 2012

On Thursday 09 February 2012 10:42:07 Thiago Macieira wrote:
> On Thursday, 9 de February de 2012 10.07.16, Jedrzej Nowacki wrote:
> > Hi,
> > 
> >   Does anybody know why we have separation between QMetaTypeId and
> > 
> > QMetaTypeId2 classes?
> Because the original QMetaTypeId that existed in Qt 4.0 lacked one important
> feature, which Harald fixed in 4.2 or 4.3.
> Before harryF's changes, the Q_DECLARE_METATYPE macro did not save the name,
> so you had to include the type's name in the registration function:
> 	qRegisterMetaType<MyType>("MyType");
> This was necessary because the type's name cannot be easily gleaned from the
> template parameter (I have a patch for that though, see
> https://codereview.qt- project.org/#change,670 ).

It was before my time, but I think it is totallty unrelated to that, since 
Q_DECLARE_METATYPE already registered the name in Qt 4.0 and that QMetaTypeId2 
is only used for builtin types.

I beleive it has been added so adding builting type do not conflicts with 
Q_DECLARE_METATYPE of the same type.

Indeed, in Qt 4.1, the list of supported metatype was quite small
But in Qt 4.2, where QMetaTypeId2 was added, that list has gained a lot of 
Without QMetaTypeId2, customer code that would have done 
Q_DECLARE_METATYPE(QStringList) yould break

> >   QMetaTypeId2 delegates all operations to QMetaTypeId by default and
> > 
> > qMetaTypeId() function is calling QMetaTypeId2. To make it more complex
> > Q_DECLARE_METATYPE is specializing QMetaTypeId but
> > Q_DECLARE_BUILTIN_METATYPE is specializing QMetTypeId2. From an user
> > perspective it is not visible, but it makes implementation complex.
> > 
> >   Can I merge QMetaTypeId and QMetaTypeId2?
> Yes. Those are not public classes.
> There was some Harmattan code that specialised them and broke when we made
> some changes in 4.7, but touching those classes is internal API.

In Qt5.0 they sure can be merged.

Maybe we will need to re-add it if we decide to add buitlins metatype that 
were not builtins before. But it is less likely now that in Qt 4.1, or maybe 
we find another trick to keep it working.

More information about the Development mailing list