我有以下代码:
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)
有人可以让我知道我应该做出哪些更改,以便当我点击按钮时,我会看到下一个屏幕?
答案 0 :(得分:0)
首先,我必须在我的系统上将require 'qt'
更改为require 'Qt'
,因为我使用了区分大小写的文件系统,并且由于兼容性原因,我建议使用正确的大小写。
一旦我能够运行您的脚本,我意识到堆栈跟踪实际上只是您提供的SystemStackError
消息。所以我看了一下,发现了一个有用的片段here :(显然你不再需要在Ruby 2.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()
的声明,我也不确定quit()
是否可以使用SLOT
进行访问。
更新:我很确定现在问题是SLOT
调用。
例如,这非常好用:
connect(exit, SIGNAL(:clicked)) { puts "Hello world." }
现在问题是quit
未在QtWidget
上实现,而是在应用程序上实现。但是,您可以关闭窗口,如果没有打开窗口,应用程序将默认终止:
connect(exit, SIGNAL(:clicked)) { close() }