[Kde-bindings] Qyoto Delegate Patch

Richard Dale rdale at foton.es
Fri Jul 13 10:55:10 UTC 2007


On Thursday 12 July 2007, Arno Rehn wrote:
> Am Donnerstag, 12. Juli 2007 schrieb Richard Dale:
> > On Thursday 12 July 2007, Arno Rehn wrote:
> > > Hi,
> > >
> > > based on the discussion Richard and I had at akademy about signals
> > > mapping onto delegates, I hacked kalyptus to generate generic delegates
> > > but keep the various overloaded 'Connect' methods. In my opinion it's
> > > simply the less ugliest possibility.
> > >
> > > Now you can say:
> > > Connect(button, SIGNAL("clicked(bool)"), delegate(bool b) {
> > > 	Console.WriteLine("Bool {0}", b);
> > > });
> > >
> > > or
> > > button.AddClickedHandler(delegate(bool b) {
> > > 	Console.WriteLine("Bool {0}", b);
> > > });
> > >
> > > Instead of an anonymous delegate you could of course give a normal
> > > method to the functions.
> > >
> > > The other possibility would have been to make also the Connect method
> > > generic, which would then look like this:
> > > Connect<bool>(button, SIGNAL("clicked(bool)"), delegate(bool b) {
> > > 	Console.WriteLine("Bool {0}", b);
> > > });
> > >
> > > With this version we would have to check what delegate type the
> > > programmer actually used and then connect to the appropiate imternal
> > > slot. So the actual amount of code generated wouldn't decrease, we'd
> > > only have less overloaded 'Connect' methods.
> > > Personally spoken, I think the first version without a generic Connect
> > > is much nicer.
> > > I uploaded a patch here since it's quite a large one:
> > > http://pumphaus.kilu.de/programming/delegate_patch.patch
> > > It also adds a new option to the CMakeLists.txt with which you can
> > > enable/disable the new experimental API (ENABLE_QYOTO_EXPERIMENTAL,
> > > disabled by default). Patch from the top level kdebindings directory,
> > > with -p0.
> >
> > I'm not keen on 100 or so extra connect methods polluting a public class
> > like QObject, and so I prefer the generic version. I think most uses of
> > this form of Connect would be with no args, or just an int arg. This is
> > why I think it was a good idea to not rush into adding delegate things to
> > the first release of Qyoto. If we have users, we can talk about use cases
> > - otherwise it is a bit hard to judge which is the least ugly solution.
>
> Yeah, because of this I didn't check this in.
>
> > Arno - now that kdedevelopers.org is hosted on a KDE Ev machine which
> > won't go missing, how about getting an account and blogging about this
> > sort of issue? Also a blog somewhere about how non-C# language work with
> > Qyoto would be really interesting. Then you would need to contact clee to
> > get the blog aggregated on kde planet org.
>
> I didn't know kdedevelopers.org is online again. I thought about blogging
> on that issue but failed to look whether kdedevelopers.org is online again.
> It will the first thing I'll do tomorrow ;)
OK, good! This was my test example to see what the generic delegate version 
would look like:

using Qyoto;
using System.Collections.Generic;

public delegate void DelegateSlot();
public delegate void DelegateSlot<T1>(T1 arg1);
public delegate void DelegateSlot<T1, T2>(T1 arg1, T2 arg2);
public delegate void DelegateSlot<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3);

public class MyClass : QObject
{

    public static int Main(String[] args) {
        QApplication app = new QApplication(args);
        QPushButton hello = new QPushButton();
        hello.Show();
		TestClass.Connect<bool>(	hello, 
									SIGNAL("clicked(bool)"), 
									delegate(bool arg1) { 
										Console.WriteLine("calling Connect()"); 
									} 
								);
        return QApplication.Exec();
    }
}

public class TestClass {
	static public void Connect<T>(QObject arg1, string arg2, DelegateSlot<T> 
arg3) {
	}
}

-- Richard




More information about the Kde-bindings mailing list