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:

  1. declare enum inside of wrapper class contains q_gadget macro.
  2. register enum using q_enum macro after that.
  3. register class containing enum: q_declare_metatype(myclass)
  4. 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 (or q_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 using q_enum; not needed in general, in scenario) enables type used inside qvariants (qt's c++98, rtti-less incarnation of c++17's std::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 in qvariant.
  • 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

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -