DIY moc – Dynamic Meta Objects
Abstract: Moc’s job is two-fold: it generates the qt_metacall() member function that dispatches incoming calls to slots and implements reading and writing of properties, and it generates the QMetaObject containing information about what signals, slots and properties are available, providing runtime introspection capabilities. All of this is fixed at compile time though, a limitation that might get into your way when using dynamic languages such as QML.
When exposing objects to a scripting language that are only known at runtime, or similarly when connecting to an IPC service, it is however possible to generate QMetaObjects dynamically, albeit using non-public Qt API. We will see how to do that, what to consider and how to use the resulting dynamic meta objects.
In order to also give these dynamically created objects sensible functionality, we will look at implementing qt_metacall() ourselves. This has applications beyond scripting in regular static C++ applications as well, for creating more powerful signal mappers for example, as it provides a way to intercept incoming signals including the ability to look at their arguments.
If you are integrating a dynamic language into your Qt application, designing a QML-based DSL, or implementing IPC code with Qt, or just want to look deep into some of the internals of QObject, this talk is for you.