QtRuby emit不工作

QtRuby emit不工作,ruby,qt,signals,slot,emit,Ruby,Qt,Signals,Slot,Emit,平台: 达尔文*-*s-MacBook-Pro.local 11.4.2达尔文内核版本11.4.2:Thu Aug 23 16:25:48 PDT 2012;根目录: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(瓶装),头 代码: require 'Qt' class Foo < Qt::Ob

平台

达尔文*-*s-MacBook-Pro.local 11.4.2达尔文内核版本11.4.2:Thu Aug 23 16:25:48 PDT 2012;根目录: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(瓶装),头

代码

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和qtbindings,但问题仍然存在。我还尝试在同一台机器上使用带有信号和插槽的PyQt,它工作起来很有魅力


有人对此有什么想法吗?这是ruby qtbindings的bug还是我做错了什么

代码似乎是正确的。这个问题只在ruby和qtbindings verions的特定组合中表现出来,现在已经过时了。

通常,在可靠地传递任何信号之前,需要启动Qt的事件循环。我在你的代码中看不到这一点。更具体地说,我缺少的是:

app = Qt::Application.new(ARGV)
app.exec

这似乎是ruby-2.0.0-p0的一个bug,qtbindings在这个版本中不能很好地工作。我在同一台机器上试用了ruby-1.9.3-p392,它可以使用qtbindings 4.8.5.2和ruby 2.0.0p247(2013-06-27修订版41674)[i686 linux]您的代码可以在Ubuntu 15.10上使用qtbindings 4.8.6。