[Kde-bindings] playground/bindings/kimono

Richard Dale Richard_Dale at tipitina.demon.co.uk
Mon Jun 19 11:27:13 UTC 2006


On Sunday 18 June 2006 17:17, Paolo Capriotti wrote:
> 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).
Yes, that looks good. I didn't know you could write '[Q_SLOT]', as opposed 
to '[Q_SLOT()]', so the version without brackets looks better. I've recently 
added slot and signal return types and values to QtRuby, and a lot of the 
changes can be copied into Qyoto. For example, there are new C++ classes 
called 'SlotReturnValue' and 'SignalReturnValue'. It would be nice to 
refactor the Qyoto code a bit to be more like the Qt4 version of QtRuby, 
with 'marshall_types.cpp/h' sources.

In slot and signal type signature a 'QWidget&' and a 'QWidget' are exactly the 
same, but a 'QWidget*' is different. So for C#, you would still need to have 
an explicit C++ type signature to use pointer types, but otherwise they could 
default to value types. For example:

[Q_SLOT]
int FooBar(QWidget arg) {
    ...
}

Would be a 'int fooBar(QWidget)' in C++, with just the method name lowercased 
(although that isn't strictly necessary and slot names can start with a upper 
case letter).

> 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();
> 	}
> }
What type of thing is 'test' here?

mytest.Clicked += test;

I don't quite see where it comes from.

> 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.
I like the look of being able to do something like 'btn.Clicked += delegate() 
{ Console.WriteLine("Hello world"); }', but rather than have a proxy temporay 
object I'd prefer we did it be generating a changed QMetaObject on the fly if 
that was possible. And just using ordinary QObject::connect() calls 
underneath.

How long is it before the .NET 2.0 version of mono is released? The various 
types of ArrayLists could also be done with generics to look more like the 
C++ originals.

-- Richard



More information about the Kde-bindings mailing list