[Kde-bindings] custom slots
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Mon Jan 23 10:55:16 UTC 2006
On Friday 20 January 2006 22:54, Thomas Moenicke wrote:
> Hi,
>
> I want to call custom slots with a c++ proxy method, registered as slot. To
> know which php-method has to be called as custom slot, the pair ("custom
> slot", "signal") can be stored in a hash table.
>
> Is there a better, more elegant solution?
> I played a bit with qt_metacall() but how to add the name and an id '_id'
> of an additional method at runtime? indexOfMethod() walks through the
> structure 'd' but I find no way to access it. I believe it will be called
> before qt_metacall is called, and if indexOfMethod() does not find the name
> of method the mechanism fails.
Another way is to override the QObject::metaObject() virtual method in php
subclasses of the QObject classes, and return a dynamically constructed
QMetaObject with any slots and signals that were defined in php. Then
override the qt_metacall() virtual method, and for any php slots marshall the
args from C++ to php, and call the php method. If the qt_metacall() wasn't
for a php slot, then call qt_metacall() in the super class, so that it will
just call an existing C++ slot. Given a list of slot and signal type
signatures as strings it is reasonably straightforward to construct a
QMetaObject.
For signals you need to add a method to a php class when a signal is defined,
and then when that method is invoked via 'emit my_method()' or similar (where
emit doesn't do anything), have some code which marshalls the args to C++
array of 'void *'s, and then calls QMetaObject::activate().
The disadvantage of using proxy methods is that you need to intervene
everytime a slot or signal is passed to a Qt method, and do something
different depending on whether the target slot is a C++ on or a php one.
Whereas if you construct QMetaObjects at runtime from the slots and signals
declared in php, you only need to override the qt_metacall() method.
-- Richard
More information about the Kde-bindings
mailing list