QtRuby发射不起作用

时间:2013-03-23 03:46:25

标签: ruby qt signals slot emit

平台

  

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

输出

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的错误还是我做错了什么?

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

代码似乎是正确的。问题只表现在ruby和qtbindings版本的特定组合上,现在已经过时了。