[Kde-bindings] Qyoto Delegate Patch

Richard Dale rdale at foton.es
Thu Jul 12 21:31:15 UTC 2007


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.

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.

-- Richard





More information about the Kde-bindings mailing list