[Kde-bindings] Qt, Qyoto buttons work intermediately

Richard Dale rdale at foton.es
Thu Feb 18 10:08:52 UTC 2010

On Thursday 18 February 2010 09:44:20 am linuxoidoz at yahoo.com.au wrote:
> So if I understand it right, if I have one class MainWindow with a button
> btn1, and another class StartWindow with a button btn2, then you use this
> Connect(button, SIGNAL("clicked()"), otherObject.btn2,
> SLOT("buttonClicked()"));
> to emit a signal buttonClicked() from btn2 in StartWindow when button btn1
> in MainWindow has been clicked?
> >you tell the meta object system to invoke "otherObject.buttonClicked()"
> >when the signal "clicked()" in the object "button" is emitted
> In C# you declare a method first as
> this.btn1.Clicked += new System.EventHandler(this.OnBtn1Clicked);
> and then implement it as
> protected virtual void OnBtn1Clicked (object sender, System.EventArgs e)
> How do you do this with Qt in C#? Sorry, I just can't understand this
> signal/slot thing without comparable examples. All I need to know is, for
> example, how to show a message box from another class and pass a variable
> to it.
> This
> 		QObject.Connect(btnAbout, Qt.SIGNAL("clicked()"), this,
> Qt.SLOT("ShowAbout(variable)"));
> 		[Q_SLOT]
> 		private void ShowAbout() {
> 			QMessageBox.About(this, "About", variable.ToString());
> 		}
> simply doesn't work. How can you pass a reference to a widget in the SLOT
> if you're saying you need to pass a type, NOT a variable, when the
> variable is invisible to the QMessageBox unless you pass it to the method.
> If you could send me a link to signal/slot C# examples, I'm happy to read,
> but this Qt-C# signal/slot theory is too different to plain C# to
> comprehend.
Look at the cannon game tutorial examples t1 to t14 - they are mainly about 
learning how to use signals and slots. You can emit signals in Qyoto, but for 
your purposes I think all you need to do it to connect up your custom slots to 
existing signals. So that is a matter of making sure that you specify the C++ 
types in the strings used in the connect statements. Not variable names, and 
not C# types.

We are trying to come up with a 'prettier' solution to connecting signals and 
slots, but every design so far has ended up being just as ugly as what we have 
now, but in different ways. However, once you get how signals and slots work, 
they are actually quite straightforward, ugly strings or not.

-- Richard

More information about the Kde-bindings mailing list