[Kde-bindings] Hacking moc-generated code

Richard Dale Richard_Dale at tipitina.demon.co.uk
Fri Sep 9 13:05:52 UTC 2005


On Friday 09 September 2005 14:55, Eric Jardim wrote:

> 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?vie
>w=markup
Yes, that looks familiar. To emit signals from python you need to dynamically 
add python methods for each signal, which in turn call 
QMetaObject::activated() once they have  converted their python args to C++.

> I also managed to put a Python plugin in QtDesigner.
>
> Things are getting very interesting ;)
I read about Boost::Python, and I'm not sure if the approach of manually 
defining wrapper code for every method and class will scale for a library the 
size of Qt/KDE with about 10000 classes and over 25000 methods. I think you 
might find you need to autogenerate the boost python wrapper code, at which 
point it might have been better to start from scratch with a Qt specific tool 
which knew about Qt memory management policies and calling conventions.

It will be interesting to compare with the python/SIP with Boost::Python, and 
with perl/ruby Smoke approaches being using at the moment.

-- Richard



More information about the Kde-bindings mailing list