我有以下代码:
require 'qt'
class Menu < Qt::Widget
slots 'on_clicked_uAuth()'
slots 'quit()'
def initialize(parent = nil)
super(parent)
setWindowTitle "Menu"
uAuth_ui
exit_ui
resize 350, 500
move 300, 300
show
end
def uAuth_ui
uAuth = Qt::PushButton.new 'Auth', self
uAuth.resize 150, 35
uAuth.move 100, 100
connect uAuth, SIGNAL('clicked()'), self, SLOT('on_clicked_uAuth()')
end
def exit_ui
exit = Qt::PushButton.new 'Exit', self
exit.resize 120, 40
exit.move 115, 420
connect exit, SIGNAL('clicked()'), self, SLOT('quit()')
end
end
app = Qt::Application.new(ARGV)
Menu.new
app.exec当我单击这两个按钮中的任何一个时,都会出现以下错误:
stack level too deep (SystemStackError)有人能让我知道我应该做什么更改,以便当我单击按钮时,我会看到下一个屏幕吗?
发布于 2016-02-03 18:54:54
首先,我必须在系统上将require 'qt'更改为require 'Qt',因为我使用区分大小写的文件系统,并且出于兼容性原因,我建议使用正确的大小写。
一旦我能够运行您的脚本,我就意识到堆栈跟踪实际上就是您提供的SystemStackError消息。所以我看了看周围,发现了一个有用的代码片段here:(显然你在Ruby2.2中不再需要它了,但我现在还没有安装它,所以我没有费心去尝试)
set_trace_func proc {
|event, file, line, id, binding, classname|
if event == "call" && caller_locations.length > 500
fail "stack level too deep"
end
}在执行应用程序之前,您可以在某个地方添加此代码,堆栈跟踪将变得更加有用:
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:2531:in `debug_level'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:2714:in `do_method_missing'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:2711:in `do_method_missing'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:2667:in `do_method_missing'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:469:in `method_missing'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:469:in `qt_metacall'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:469:in `method_missing'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:469:in `qt_metacall'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:469:in `method_missing'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:469:in `qt_metacall'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:469:in `method_missing'因此,不知何故,它陷入了调用一个不存在的方法的无休止循环中(因此堆栈级别最终太深)。
现在我无法修复您的问题,但似乎缺少某些方法。我看不到on_clicked_uAuth() anywhere的声明,我也不确定是否可以通过这样的SLOT访问quit()。
更新:现在我非常确定问题出在SLOT调用上。例如,这可以很好地工作:
connect(exit, SIGNAL(:clicked)) { puts "Hello world." }现在这里的问题是,quit不是在QtWidget上实现的,而是在应用程序上实现的。但是,您可以只关闭窗口,如果没有其他窗口打开,默认情况下应用程序将终止:
connect(exit, SIGNAL(:clicked)) { close() }https://stackoverflow.com/questions/35166937
复制相似问题