views:

40

answers:

1

I've been setting up a Qt gui using QtJambi and JRuby. So far things have gone well. I'm ready to start setting up connections, however, many of the signals don't seem to be visible from jruby. For example, if I print out the methods of QPushButton, I don't see any method called "clicked" for me to build a connection from.

I found this link regarding QtJambi and Jython, which may be related, but I don't think this is actually my problem.

http://lists.trolltech.com/qt-jambi-interest/2007-03/thread00053-0.html

How can I make these signals of my Qt objects visible to JRuby to connect to?

A: 

I got an answer from Vladimir Kirichenko from the QtJambi mailing list, which cleared things up.

Basically, one has to implement the method_missing method, which allows the signals to be seen when I called methods.

class com.trolltech.qt.gui::QWidget
  def method_missing(sym)
    if sym.id2name.start_with?("signal_")
      name = sym.id2name[7, sym.id2name.length]
      f = self.getClass.fields.select {|f| f.name == name }.first
      f.get(self)
    else
      nil
    end
  end
end

Then I can just do something like

$object_action.signal_changed.connect(...)
voodoogiant