[Kde-bindings] playground/bindings/kimono

Paolo Capriotti p.capriotti at gmail.com
Sun Jun 18 16:17:47 UTC 2006


On 6/9/06, Jason D. Clinton <me at jasonclinton.com> wrote:
> On Thursday 08 June 2006 17:18, Paolo Capriotti wrote:
> > This is great! We do have to polish the interface a little bit, but
> > the hardest work is done.
>
> BTW, I passed along this great news to the guys hanging around in the #mono
> channel on IRC. While it was generally praised, there was some criticism of
> not using the C# event feature.
>
> Is the SIGNAL/SLOT system used to maintain compatibility with the existing Qt
> docs? How hard will it be to get the C++ method signature to be optional
> (might help with making the code samples prettier)?

Last week I've been working on Qyoto (unfortunately, I didn't have an
internet connection, nor I will for the next week either) and
implemented optional signatures, so you can write

[Q_SLOT]
public void TestSlot(int x) {
  // ...
}

and the signature is automatically inferred (as "testSlot(int)", in
this example).

I've also been trying to add support for a better sintax in defining
and using slot and signals, and I've come to make the following
example work:

class Test {
	class MyWidget : QWidget {
		public MyWidget() : base((QWidget)null) {
			QPushButton quit = new QPushButton("quit", this);
			quit.Clicked += QApplication.Quit;
			
			QPushButton mytest = new QPushButton("test", this);
			mytest.Clicked += test;
			
			QVBoxLayout layout = new QVBoxLayout();
			layout.AddWidget(quit);
			layout.AddWidget(mytest);
			SetLayout(layout);
		}
		
		[Q_SLOT]
		public void test() {
			Console.WriteLine("************ IT WORKS **************");
		}
	}

	public static void Main(string[] args) {
		new QApplication(args);
		MyWidget main = new MyWidget();
		main.Show();
		QApplication.Exec();
	}
}

The idea is to generate special events corresponding to Qt signals,
which override add and remove to make connections with the original
signals. For example, when you write (using C# 2)

btn.Clicked += delegate() { Console.WriteLine("Hello world"); }

the "clicked()" signal of btn is connected with a predefined slot of a
temporary object, which simply calls the delegate. The temporary
object is like this:

	public class SlotInvocation0 : QObject {
		private Signal slot;
		
		public SlotInvocation0(Signal slot) {
			this.slot = slot;
		}
		
		[Q_SLOT]
		public void ProxySlot() {
			slot();
		}
	}

where Signal is defined as:

public delegate void Signal();

The number 0 in SlotInvocation0 is because of the multiple versions of
this class that are needed to handle slots with parameters.
Unfortunately, I couldn't help using generics, so this works only
within .NET 2.0.

Paolo



More information about the Kde-bindings mailing list