QtRuby GridLayout-未定义的方法' addWidget'

时间:2014-07-01 00:20:53

标签: ruby qt qtruby

我正在使用QtRuby处理GUI项目。但是,只要我添加代码以在GridLayout对象中使用MainWindow,我就会收到此错误:

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

1 个答案:

答案 0 :(得分:1)

我想出了我的问题 - 我试图在没有视图的情况下向布局添加模型。这是我的固定代码:

# ...
@layout = Qt::GridLayout.new
@fsModel = Qt::FileSystemModel.new
@fsView = Qt::TreeView.new
@fsView.setModel(@fsModel)
@layout.addWidget(@fsView, 0, 0, 1, 1)
@editor = EditorWidget.new
@layout.addWidget(@editor, 1, 0, 4, 1)
# ...