[Kde-bindings] Qyoto: SIGNALS/SLOTS

Richard Dale Richard_Dale at tipitina.demon.co.uk
Tue Dec 13 21:59:53 UTC 2005

On Tuesday 13 December 2005 21:06, Thomas Moenicke wrote:
> Richard Dale wrote:
> > >                 [SIGNAL]
> > >                 public void EmitStuff ()
> > >                 {
> > >                         Emit("EmitStuff()");
> > >                 }
> do you have to modify the language parser to provide this syntax? Or is it
> better to find an exception which can be intercepted? Or generally without
> additional syntax? I ask because I have to find a solution similary to
> this. I want to handover signals to an engine which calls the right php
> function defined by user.
The above is one of Adam's suggestions that Qt# used. Or this one has the 
signal defined just as a type signature in an interface, which is transformed 
into a method call by using a C# transparent proxy.

               public void EmitStuff();
              ((MyInterface) Emit()).EmitStuff()

In C++ a signal is transformed into from a type declaration to a method call 
by the moc. So in other languages need to do something similar. 

In qtruby a signal is defined like this:

class MyClass < Qt::Object
    signals 'emitStuff()'

    def foobar
        emit emitStuff()

The "signals 'emitStuff()'" is a method call that is called when the ruby code 
is parsed (a bit like C# Attributes are). I'm not sure if there is something 
similar in php.

An emitStuff() method is added to the 'MyClass', which is then called by the 
'emit emitStuff()' statement, and the QMetaObject created at runtime has a 
corresponding signal entry. Then inside the dynamically added 'emitStuff()' 
method, the ruby args are marshalled to C++ ones and QtMetaObject::activate() 
is called.

In the C++ class EmitSignal in qtruby/rubylib/qtruby/Qt.cpp:

		_obj->metaObject()->activate(_obj, _id, o);

Slots are invoked via qt_metacall() in Qt4 - I've been wrongly talking about 
that instead of activate() for signal invocations.

-- Richard

More information about the Kde-bindings mailing list