开发者

Setting up QtJambi connections from JRuby

开发者 https://www.devze.com 2023-01-21 05:10 出处:网络
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 ex

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 regar开发者_StackOverflowding 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?


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(...)
0

精彩评论

暂无评论...
验证码 换一张
取 消