c++ - Is Qt's meta system really that tedious? -
i use qt's reflection mechanism since c++ lacks of feature. seems work, calling macros , helper functions tedious. example register enum proper meta type had go through following steps:
- declare enum inside of wrapper class contains
q_gadget
macro. - register enum using
q_enum
macro after that. - register class containing enum:
q_declare_metatype(myclass)
- call
qregistermetatype<..>()
type of wrapping class , each declared enum.
now know of steps can omitted if part of full functionality not required. not looking for, need use enums within signals , need able the meta method of signal , query it's parameters type.
but still can't thinking there must better/simpler way this.
unfortunately, can't less that.
q_gadget
(orq_object
, qobject subclasses) means "generate meta-object information class".q_enum
means "generate meta-enum information particular enum". 1 might argue (public?) enumerations in registered class should automatically registered. since has cost (binary size), , use c++, don't want pay enums we're never going use in meta-object system, it's opt-in.q_declare_metatype
(not needed on enum if you're usingq_enum
; not needed in general, in scenario) enables type used insideqvariant
s (qt's c++98, rtti-less incarnation of c++17'sstd::any
). whether want or not depends on type. "value types" should have it, again, generates code may not want pay for. also, applies "value types" -- registration requires type have public default constructor, public copy constructor, public copy assignment, public destructor. if you've got class not have these, can't use macro => can't wrap inqvariant
.qregistermetatype
registers aforementioned constructors/destructors in table @ runtime, enabling have unique id type (required if want identify types in method signatures), dynamically create or destroy instances of type (required, amongst other things, implement queued connections: qt needs generic way copy signal's arguments event sent target thread, , destroy such arguments later), use q_property subsystem.
depending on need need subset of of this.
Comments
Post a Comment