平台:



Ruby :



Qt :



代码:

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

最佳答案

通常,需要先启动Qt的事件循环,然后才能可靠地传递任何信号。我在您的代码中看不到。更具体地说,我所缺少的是:

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

关于ruby - QtRuby发射不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15583114/

10-11 02:33