平台:
Darwin * -*s-MacBook-Pro.local 11.4.2 Darwin内核版本11.4.2:8月23日星期四16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64
Ruby:
ruby 2.0.0p0(2013-02-24修订版39474)[x86_64-darwin11.4.2](由rvm安装)
Qt:
qt:稳定4.8.4(瓶装),HEAD
代码:
require 'Qt'
class Foo < Qt::Object
signals :my_signal #also tried 'my_signal()'
slots 'my_slot()'
def initialize(parent = nil)
super(parent)
puts "connecting signal and slot"
Qt::Object.connect(self, SIGNAL('my_signal()'), self, SLOT('my_slot()'))
# also tried => connect(self, SIGNAL('my_signal()'), self, SLOT('my_slot()'))
end
def emit_my_signal
puts "sending signal"
emit my_signal
end
def my_slot
puts "received message from signal"
end
end
o = Foo.new
o.emit_my_signal
Run Code Online (Sandbox Code Playgroud)
输出: …