[Kde-bindings] Qt, Qyoto buttons work intermediately

Arno Rehn arno at arnorehn.de
Tue Feb 16 14:26:12 UTC 2010


On Tuesday 16 February 2010 14:59:48 linuxoidoz at yahoo.com.au wrote:
> OK, here's the test project attached to prove my point.
> 
> 1. Currently, MainWindow.cs has a class MainWindow which has a InitUI()
> property which has a ShowAbout() slot Connect(startWin.btnAbout,
> SIGNAL("clicked()"), this, SLOT("ShowAbout()"));
> 
> 2. MainWindow.cs has a slot GoToPage2() with a slot
> Connect(startWin.btnAbout, SIGNAL("clicked()"), this, SLOT("ShowAbout()"));
> 
> 3. Both StartWindow.cs and SecondWindow.cs have their ShowAbout() slots
> disabled (commented out).
> 
> 4. The way it works now is that you can switch between the stack pages,
> click on the Show About buttons and they will pop up messages with a page
> number.
> 
> 5. Now comment out the both ShowAbout() slots in MainWindow.cs and
> un-comment out those in StartWindow.cs and SecondWindow.cs and see what
> happens.
> 
> 6. On my computer, I can still switch between the pages (because the slots
> are in the MainWindow), but none of the Show About buttons work (because
> they are in separate classes). This is what I meant. Is this a bug?
> There's no documentation on Qyoto, so I've got no idea how and where to
> use these signals/slots in C#.
Yes. You didn't understand how signals and slots work. This explains it all: 
http://doc.trolltech.com/4.6/signalsandslots.html .

Short summery: This line
QObject.Connect(btnAbout, Qt.SIGNAL("clicked()"), mainwin, 
Qt.SLOT("ShowAbout(mainwin, page)"));
connects to a method (slot) ShowAbout() which takes two arguments: one of type 
mainwin, one of type page. There are two reasons why this won't work:

1. The signal doesn't provide any parameters, but the slot does. How is this 
supposed to work?
2. You give a method signature to the SLOT method, i.e. mainwin and page are 
expected to be types, not variables. But there is no type called 'mainwin' and 
there is also no type called 'page'. Both are variables. But this is not how 
signals and slots work. SIGNAL and SLOT expect _signatures_, not method call 
expressions.

Furthermore, you can only define slots in QObject subclasses. Otherwise you 
have to use delegate connections. (QObject.Connect(sender, SIGNAL(/*signal*/), 
delegate { /* ... */ });)

Please make yourself familiar with the Qt toolkit. Qyoto doesn't need any 
documentation about signals and slots. It's merely a wrapper with some 
syntactic sugar for the Qt toolkit.

And again the tip: Make each page a subclass of QWidget. You can then define 
signals and slots in them and don't have to mess around with connecting 
signals from pushbuttons to slots in the mainwindow (i.e. completely unrelated 
widgets).

-- 
Arno Rehn
arno at arnorehn.de



More information about the Kde-bindings mailing list