首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QtRuby发出不起作用

QtRuby发出不起作用
EN

Stack Overflow用户
提问于 2013-03-23 03:46:24
回答 2查看 642关注 0票数 13

平台

达尔文*-*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 (瓶装),头部

代码语言:javascript
复制
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

输出

代码语言:javascript
复制
connecting signal and slot
sending signal

使用Qt.debug_level = Qt::DebugLevel::High的输出

代码语言:javascript
复制
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,在同一台机器上安装了信号和插槽,它的工作原理就像一种魅力。

有人对此有什么想法吗?是红宝石的错误还是我做错了什么?

EN

回答 2

Stack Overflow用户

发布于 2016-01-19 19:32:35

通常,需要启动Qt的事件循环,然后才能可靠地传递任何信号。我从你的密码里看不出来。更具体地说,我错过的是:

代码语言:javascript
复制
app = Qt::Application.new(ARGV)
app.exec
票数 1
EN

Stack Overflow用户

发布于 2016-01-11 09:09:08

代码似乎是正确的。这个问题只表现在红宝石和qtbindings的特殊组合上,而这两者现在已经过时了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15583114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档