[Development] constexpr and qMetaTypeId<>()

Stephen Kelly stephen.kelly at kdab.com
Thu Sep 12 09:47:26 CEST 2013


On Wednesday, September 11, 2013 14:29:44 achartier at fastmail.fm wrote:
> Hello,
> 
> I'd like to use qMetaTypeId<>() in a constexpr expression. I have my own
> custom type declared as such:
> 
> class MyCustomClass : public QObject
> {
>      Q_OBJECT
> 
>      // ...
> };
> 
> Q_DECLARE_METATYPE(MyCustomClass*)

Unless you need to stay Qt 4 compatible, you can remove this line. Pointers to 
QObject derived types are automatically treated as metatypes if needed.

> 
> I then try the following:
> 
> constexpr qint32 metaTypeId = qMetaTypeId<MyCustomClass*>();

This only works for built-in metatypes which have an id value defined in the 
QMetaType::Type enum.

Thanks,

-- 
Join us in October at Qt Developer Days 2013 - https://devdays.kdab.com

Stephen Kelly <stephen.kelly at kdab.com> | Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-Independent Software Solutions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130912/32a1b64c/attachment.sig>


More information about the Development mailing list