[Kde-bindings] Qt, Qyoto buttons work intermediately

Arno Rehn arno at arnorehn.de
Sat Feb 20 15:19:40 UTC 2010


On Saturday 20 February 2010 16:12:31 linuxoidoz at yahoo.com.au wrote:
> > That sounds more like programming issues in general than Qt issues.
> > 
> > 1) sounds like a bit of a bad idea in general - more sensible would be
> > to have the StartWindow fire an event, have the MainWindow subscribe to
> > the event, and then have a method in the MainWindow add the page when
> > the event occurs. That way the pages are only concerned with their own
> > stuff, not with other things.
> > 
> > 2) Probably the same - keep things separated so that the page doesn't
> > know about the construction of the main window, but use events so that
> > the main window can do whatever it needs to.
> > 
> > Tight coupling, like it sounds like you have, is generally going to
> > cause you problems in the long run :)
> 
> Well, there may be programming issues, but what I'm trying to figure out is
> purely Qt - how do you pass a variable in a signal/slot?
> 
> In normal C# you would do:
> 
> onButtonOKClicked() {
> 	string str1 = "string";
> 	ChangeText(str1);
> }
> 
> ChangeText (string str2) {
> 	txtEdit.Text = str;
> }
> 
> but in Qt this doesn't work:
> 
> signal(btnOK, SIGNAL("clicked()"), this, SLOT("ChangeText(str1)")); - it
> says no such slot
Nope, it's the same in Qt. To be more precise, in C# you would do (pseudo-
code):

button.Clicked += onButtonOkClicked;
...
onButtonOkClicked() {
	ChangeText(str1);
}
ChangedText(string str) {
	txtEdit.Text = str;
}

In Qt it's exactly the same:

Connect(button, SIGNAL("clicked()"), this, SLOT("onButtonOkClicked()");
...
onButtonOkClicked() {
	ChangeText(str1);
}
ChangedText(string str) {
	txtEdit.Text = str;
}

What you were trying to do with your Connect() statement above is similar to 
doing this in C#:

button.Clicked += onButtonOkClicked(myStringHere);

which will obviously NOT work.
Remember, connecting signals and slots is just the same as subscribing to a C# 
event.

-- 
Arno Rehn
arno at arnorehn.de



More information about the Kde-bindings mailing list