[Kde-bindings] How to get the sender object in a SLOT in Qyoto?
vronskij
vronskij at gmail.com
Thu Apr 30 22:33:07 UTC 2009
Hi,
I have two buttons in the window. Both are plugged to the same method.
How do I tell between them?
For example, I would like to print the text of the button, that was clicked.
None of the signals of the QPushButton or the QAbstractButton do send
a button object or similar.
In the QtJambi binding (Java + Qt), it is done in the following way:
QPushButton sender = (QPushButton) QSignalEmitter.signalSender();
How do I get a reference to the signal sender?
The following code is a complete example of what I mean.
Thanks,
jan bodnar
using System;
using Qyoto;
public class QyotoApp : QWidget {
public QyotoApp() {
SetWindowTitle("QPushButtons");
InitUI();
Resize(300, 150);
Move(300, 300);
Show();
}
void InitUI() {
QPushButton apply = new QPushButton("Apply", this);
QPushButton cancel = new QPushButton("Cancel", this);
Connect(apply, SIGNAL("clicked()"), this, SLOT("OnClicked()"));
Connect(cancel, SIGNAL("clicked()"), this, SLOT("OnClicked()"));
apply.Move(20, 20);
cancel.Move(110, 20);
}
[Q_SLOT]
void OnClicked() {
//QPushButton sender = (QPushButton) QSignalEmitter.signalSender();
//Console.WriteLine(sender.Text);
Console.WriteLine("click");
}
public static int Main(String[] args) {
new QApplication(args);
new QyotoApp();
return QApplication.Exec();
}
}
More information about the Kde-bindings
mailing list