[Development] Why does Q_ENUM() need qRegisterMetaType()?

Tom Isaacson Tom.Isaacson at navico.com
Thu Jul 4 12:43:00 CEST 2019


> The problem is that moc only generates the code that calls qRegisterMetaType if it sees Q_DECLARE_METATYPE. Actually, it does a bit more than that. It could as well do it for Q_ENUM type, just not implemented yet.
>
> We should consider doing it for all the types used in signals/slots/properties. 
>  But it does not do it because that could be a potential breaking change for forward declared types.
> Maybe something for Qt6.

It's very confusing. You said yourself on https://woboq.com/blog/q_enum.html that "These enums are automatically declared as a QMetaTypes (no need to add them in Q_DECLARE_METATYPE anymore)." So Q_ENUM replaces Q_DECLARE_METATYPE and provides additional functionality but requires you to add an additional call to qRegisterMetaType? That seems backward.

Can I use Q_DECLARE_METATYPE and Q_ENUM and avoid qRegisterMetaType?

Tom Isaacson



More information about the Development mailing list