[Kde-bindings] Hacking moc-generated code

Eric Jardim ericjardim at gmail.com
Fri Sep 9 12:55:24 UTC 2005


2005/9/9, Richard Dale <Richard_Dale at tipitina.demon.co.uk>:

> I wrote a blog about the format of the Qt4 QMetaObjects here:
> http://www.kdedevelopers.org/node/1149
> 

And I read it. It helped a lot ;)


You can override QObject::metaObject() as it's a virtual method, and then
> construct a QMetaObject dynamically and return that instead of the usual
> statically allocated one. 


Sure, after hours examining moc generated code, I understood some of the way 
how it worked. 


It just comes down to constructing a string table full of
> null terminated strings, and a corresponding array of numeric pointers 
> that
> give the offsets of the strings. 


This is quite straightforward. The problem was if Qt cached the 
QMetaObjects. If it did it, our work would be completely lost. But it 
queries it all the time, and that is the right approach. Objects are subject 
to change their structure dynamically.

Qt/C++ moc generated objects have static(local shared) and static(immutable) 
QMetaObject. Now, we need "not shared" and "mutable" QMetaObjects. Say, we 
can change the metaobject of a class, or even a single instance. In Python 
this is completely normal. 

This means that I can, in Python, create, change or delete signal and slots 
dynamically (bye, bye moc)! The next step would be classinfo, properties and 
interfaces.


A slot is invoked via QObject::qt_metacall() which is also a virtual method
> that you can override. You need to marshall the arguments from C++ format
> your scripting language from an array of 'void *'s that qt_metacall()
> expects.


Yeah! I have managed this. And it is a very interesting approach. 


To emit a signal you need to call QObject->metaObject()->activate() with 
> your
> scripting languages args converted to C++ ones in the same 'void*' array 
> for
> qt_metacall().
> 

I sugest you reading what I did in python-qt4:
http://svn.berlios.de/viewcvs/python-qt4/trunk/PythonQt/PythonQObject.h?view=markup

I also managed to put a Python plugin in QtDesigner. 

Things are getting very interesting ;)

[Eric Jardim]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20050909/45fd52dd/attachment.html>


More information about the Kde-bindings mailing list