2

我正在使用 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
4

1 回答 1

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)
# ...
于 2014-07-01T19:40:52.057 回答