平台:
达尔文*-*s-MacBook-Pro.local 11.4.2达尔文内核版本11.4.2:清华8月23日16:25:48 PDT 2012;根:xnu-1699.32.7~1/ x86_64 _X86_64
Ruby:
Ruby2.0.0p0 (2013-02-24修订版39474) 64-darwin11.4.2
Qt:
qt:稳定4.8.4 (瓶装),头部
码
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输出
connecting signal and slot
sending signal使用Qt.debug_level = Qt::DebugLevel::High的输出
Munged method names:
QObject$
QObject?
QObject#
candidate list:
QObject* QObject::QObject(QObject*) (smoke: 0 index: 3804)
matching => smoke: 0 index: 3804
QObject* (u) score: 2
match => smoke: 0 index: 3804 score: 2 chosen: 3804
setCurrentMethod(smokeList index: 0, meth index: 3804)
connecting signal and slot
Searching for QObject#connect
Munged method names:
connect#$#$
candidate list:
static bool QObject::connect(const QObject*, const char*, const QObject*, const char*) (smoke: 0 index: 3850)
matching => smoke: 0 index: 3850
const QObject* (QObject) score: 3
const char* (s) score: 1
const QObject* (QObject) score: 3
const char* (s) score: 1
match => smoke: 0 index: 3850 score: 8 chosen: 3850
setCurrentMethod(smokeList index: 0, meth index: 3850)
sending signal它似乎没有任何作用。我也尝试过重新安装qt和qtbinding,但问题仍然存在。我还试了一下PyQt,在同一台机器上安装了信号和插槽,它的工作原理就像一种魅力。
有人对此有什么想法吗?是红宝石的错误还是我做错了什么?
发布于 2016-01-19 19:32:35
通常,需要启动Qt的事件循环,然后才能可靠地传递任何信号。我从你的密码里看不出来。更具体地说,我错过的是:
app = Qt::Application.new(ARGV)
app.exec发布于 2016-01-11 09:09:08
代码似乎是正确的。这个问题只表现在红宝石和qtbindings的特殊组合上,而这两者现在已经过时了。
https://stackoverflow.com/questions/15583114
复制相似问题