[Kde-bindings] Qyoto: SIGNALS/SLOTS

Adam Treat treat at kde.org
Tue Dec 13 17:10:18 UTC 2005


Hi all, I've been watching your discussion of SIGNALS/SLOTS for Qyoto and I 
wanted to offer up how this was solved in Qt# as I think it might reduce the 
work for you guys...

Attached are three files that should be pretty much self contained drop in 
replacements for a signal/slot binding for Qyoto.  The first one 
'SigSlots.cs' will give you signal/slot functionality for C# <--> C# 
signals/slots and the second one 'NativeSigSlots.cs' will give you C++ <--> 
C# signals/slots as well as C# <--> C++ signals/slots.

Finally, the file 'emit.cs' will show you how it all works.

Here is what it looks like:

namespace QtSamples
{
        using Qt;
        using System;

        public class EmitSample: QVBox
        {
                public EmitSample (): base ()
                {
                        QPushButton pb = new QPushButton ("Emit Sample", 
this);

                        //pb.SIGNAL["Clicked()"] += 
this.SIGNAL["EmitStuff()"];
                        //this.SIGNAL["EmitStuff()"] += 
this.SLOT["PrintStuff()"];
                }
                
                [SIGNAL]
                public void EmitStuff ()
                {
                        Emit("EmitStuff()");
                }

                [SLOT]
                public void PrintStuff ()
                {
                        Console.WriteLine ("Emitted 'EmitStuff()'");
                }
                
                public static void Main (string[] args)
                {
                        QApplication app = new QApplication (args);
                        EmitSample es = new EmitSample ();
                        app.SetMainWidget (es);
                        es.Show ();
                        app.Exec ();
                }
        }
}

Feel free to use or ignore as is you like.

Cheers,

Adam

On Tuesday 13 December 2005 10:51 am, Arno Rehn wrote:
> Am Montag, 12. Dezember 2005 18:01 schrieb Richard Dale:
> > On Sunday 11 December 2005 14:39, Arno Rehn wrote:
> > > > I got this wrong, it should look like this:
> > > >
> > > > ((IQApplicationSignals) myInstance.Emit()).LastWindowClosed();
> > > >
> > > > And the interface for a class would need to extend the signals
> > > > interface for its superclass. So in the case above the
> > > > IQApplicationSignals interface would need to extend the
> > > > IQObjectSignals interface. But this doesn't really fit in with
> > > > delegates.
> > > >
> > > > > > And it would be forwarded to SignalInvocation.Invoke(), in a
> > > > > > similar manner to how ordinary method calls get diverted to
> > > > > > SmokeInvocation.Invoke() at the moment.
> > >
> > > We don't need a thing like SignalInvocation if all the signal are
> > > delegates. With QObject.Emit() we would just call an delegate. I
> > > wouldn't use interaces at all, just delegates which are declared in the
> > > class directly. The delegates would be inherited by derived classes,
> > > too.
> >
> > I think we might need two ways of emitting signals; one which looked as
> > Qt/C++ like as possible, and the other which looks as C#/delegate like as
> > possible. I'm not sure if it's actually possible to do it with delegates
> > though. The QObject.Emit() syntax above can definately be made to work
> > though.
>
> That's exactly what I was thinking of ;) .
>
> > > > > > But slots are easiest to get working first though, and marking
> > > > > > them with attributes like you've done looks pretty good to me.
> > > >
> > > > I think the slots need to be marked as slots, along with the C++ type
> > > > signature that would be used for constructing the QMetaObject entry
> > > > for it. Like this:
> >
> > ...
> >
> > > Looks very good, but my question: How do we connect a native Qt-signal
> > > to a C#-method ? Can we trap these signals and then call a C#-method?
> > > Or can we connect a C++ signal to a C#-method directly?
> >
> > We can trap signal calls by overriding the QObject::qt_invoke() method.
> > ...
>
> Where do you get the QObject::qt_invoke() from? I looked in the Qt-docs and
> in every header-file used by QObject.h . I can't find anything like this.
> The only objects with a qt_invoke() are the Active Qt things.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: emit.cs
Type: text/x-c++src
Size: 864 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20051213/330354ce/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NativeSigSlots.cs
Type: text/x-c++src
Size: 15274 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20051213/330354ce/attachment-0001.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SigSlots.cs
Type: text/x-c++src
Size: 20335 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20051213/330354ce/attachment-0002.cpp>


More information about the Kde-bindings mailing list