gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:25:54 24 4
gpt4 key购买 nike

我正在使用 QtRuby 开发一个 GUI 项目。但是,一旦我在我的 MainWindow 对象中添加了使用 GridLayout 的代码,我就开始收到此错误:

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

最佳答案

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

# ...
@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)
# ...

关于ruby - QtRuby GridLayout- 未定义的方法 'addWidget',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24500798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com