我正在使用 QtRuby 开发一个 GUI 项目。但是,一旦我添加代码以GridLayout
在我的MainWindow
对象中使用 a ,我就开始收到此错误:
mainwindow.rb:37:in `method_missing': undefined method `addWidget' for #<Qt::GridLayout:0x0000000221cbc0 objectName=""> (NoMethodError)
from mainwindow.rb:37:in `initialize'
from main.rb:5:in `new'
from main.rb:5:in `block in <main>'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:2652:in `instance_eval'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:2652:in `run_initializer_block'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:459:in `initialize'
from /usr/lib/ruby/vendor_ruby/2.1.0/Qt/qtruby4.rb:459:in `initialize'
from main.rb:4:in `new'
from main.rb:4:in `<main>'
这是我的 MainWindow 类的代码:
require 'Qt4'
require_relative '../eventhandler.rb'
require_relative '../editor/editorwidget.rb'
class MainWindow < Qt::MainWindow
# ...
def initialize(parent = nil)
super(parent)
# ...
@layout = Qt::GridLayout.new
@fsModel = Qt::FileSystemModel.new
@layout.addWidget(@fsModel, 0, 0, 1, 1)
@editor = EditorWidget.new
@layout.addWidget(@editor, 1, 0, 4, 1)
end
end