Closed glowiak closed 1 year ago
sender() is protected function of QObject. If you are in a QObject slot just use it. https://doc.qtjambi.io/6/qtjambi/io/qt/core/QObject.html#sender() What are you missing? Can you give me a code example?
for (int i = 0; i < 9; i++)
{
this.numberB[i] = new QPushButton("" + (i + 1), this.win);
this.numberB[i].setGeometry(bx, by, bw, bh);
this.numberB[i].clicked.connect(this, "numb_clicked()");
if (i == 2 || i == 5)
{
bx = bxb;
by += bh;
} else
bx += bw;
}
[...]
public void numb_clicked()
{
System.out.println("clicked button"); // placeholder
}
The class that invokes it all is not descend of QWidget, but it has a private QMainWindow win variable.
I recommend using QButtonGroup instead. It provides signals sending the used button. There is no way to get the current sender without using QObject slots. That's similar to C++.
@omix How to use the slots? I have never seen these in Java before.
is there any documentation about them or something like that (for Java)?
-_-
@omix How to use the slots? I have never seen these in Java before.
All methods in a QObject subclass can be used as slots, as you can read in the QtJambi how-to pages. There, you can access the protected member method QObject.signal()
.
Nevertheless, using QButtonGroup
is the better way to do what you try to do.
Can you provide an example of the use of slots?
Can you provide an example of the use of slots?
Thank you
How to get sender (like the sender() C++ function) in a connected function?
Or any other way to pass arguments when connecting. I have searched for this for a long time and haven't found any solution.
Thanks in advance.