[Kde-bindings] Hacking moc-generated code

Eric Jardim ericjardim at gmail.com
Wed Aug 31 05:33:02 UTC 2005


2005/8/31, Marcus <mathpup at mylinuxisp.com>:
> 
> I would like to hear more about this because getting signals and slots 
> working
> seems to be one of the hardest parts. I understand that Qt 4.x makes some
> changes, but I also gather that there is still a great deal of voodoo in 
> the
> moc-generated code.


Well, actually, signals and slots are working normally in python-qt4. I used 
a simple approach. I created dispatcher classes for each type of slot. It is 
impossible to connect a signal to a Python function. There must be a C++ 
slot. So I have a dispatcher class for every possible signature ex:
PythonSlot_int_int -> void slot(int, int)
and so on. Of course I have a script that write this code for me. You just 
have to say (textualy) which signatures you want to generate.

It is the only way I see to make it works. The limitation of this approach 
are new types of slot signatures. Well, we can solve this creating a central 
registry for slot dispachers. Hey, remember now... I've made this :) But 
needs more testing.
Returning to MOC, I just need to play with it, only because if I want to run 
Python extended classes (of QObject/QWidget) on C++ (like embedded C++ or 
using Python objects in QtDesigner). I am studing it, but I am not very sure 
that it will work. 

The problem is that the C++ metaobject is static. We need dynamic 
metaobjects! And that is the whole trick.


When I have worked on schemes to interact with signals and slots, I have
> always been torn between using things are not part of the Qt API whose
> details can only be discovered by reading the files that moc generates OR
> writing portable but complicated, bulky code with a great deal of 
> potential
> overhead. Qt goes to great lengths to make C++ less dangerous for
> programmers, but many of the techniques used make it difficult for non-C++
> languages to use Qt.
> 

Sure, but I think it is getting better. Try python-qt4 source and see what I 
did. I'll continue studing the moc files.

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


More information about the Kde-bindings mailing list