-
As a preface, I'm a Ruby developer who is looking into using jRuby and QtJambi together for a hobby project. My Java is near non-existent, having only bits and pieces I remember from my high school class. In an effort to make the code follow a more Ruby-centric style, I'm wondering if there's a way to connect a signal to a slot that contains "Object" types as its parameters. I started with something simple to make sure I got the basic understanding of establishing a connection. import io.qt.widgets.*;
class Foobar extends QWidget {
void onChanged(int arg) { System.out.println("hi"); }
}
public class Test {
public static void main(String[] args) {
QApplication.initialize(args);
QMainWindow mainwin = new QMainWindow();
QSpinBox spinner = new QSpinBox(mainwin);
Foobar foo = new Foobar();
spinner.valueChanged.connect(foo::onChanged);
mainwin.show();
QApplication.exec();
QApplication.shutdown();
}
} ...which works beautifully by outputting "hi" to the console whenever the spinbox value updates. After I update the slot to I'm wondering if there is a way to do what I want (or through some other means if "Object" is not the solution), and hopefully translate that onto the Ruby side of things. It seems like this used to be possible back with the old TrollTech versions from what I can make sense of in this decade-old git repo (https://github.com/CeesZ/qt_connect/blob/master/lib/qt_connect/qt_jbindings.rb). The idea is to have this middle-man class with 10 slots (one for each of the 0-9 "Object" parameters) that a signal would connect to, which would then call the actual receiver's method. Thanks~ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Actually, your connection is never initialized and spinner.valueChanged.connect(v->foo.onChanged(v)); |
Beta Was this translation helpful? Give feedback.
Actually, your connection is never initialized and
connect()
returnsnull
. That is because the signal-slot connection is created natively, i.e. by Qt. Qt cannot connect signal parameterint
to slot parameterQVariant
(=Object). Initialize the connection with lambda expression instead: