Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要从Qt4ruby表单的文本编辑(textbox)中获取信息,并传递回控制台的字符串_Ruby_User Interface_Qt4_User Controls - Fatal编程技术网

需要从Qt4ruby表单的文本编辑(textbox)中获取信息,并传递回控制台的字符串

需要从Qt4ruby表单的文本编辑(textbox)中获取信息,并传递回控制台的字符串,ruby,user-interface,qt4,user-controls,Ruby,User Interface,Qt4,User Controls,我认为这个问题最好用代码来描述。我确信解决方案很接近,我只是一直没能找到。我一直在浏览QT4API以及做教程。以下是我目前的代码: require 'Qt4' class PictureCommentForm < Qt::Widget def initialize(parent = nil) super() #setFixedSize(300, 100) @comment_text = nil picture = Qt::Label.new()

我认为这个问题最好用代码来描述。我确信解决方案很接近,我只是一直没能找到。我一直在浏览QT4API以及做教程。以下是我目前的代码:

require 'Qt4'

class PictureCommentForm < Qt::Widget
  def initialize(parent = nil)
    super()
    #setFixedSize(300, 100)

    @comment_text = nil

    picture = Qt::Label.new()
    image = Qt::Image.new('image.jpeg')
    picture.pixmap = image

    comment = Qt::LineEdit.new()

    layout = Qt::VBoxLayout.new()
    layout.addWidget(picture)
    layout.addWidget(comment)
    setLayout(layout)

    connect(comment, SIGNAL('returnPressed()'), self, setCommentText(comment.text) )
  end

  def setCommentText(text)
    @comment_text = text
    $qApp.quit()
  end
end

app = Qt::Application.new(ARGV)
comment_form = PictureCommentForm.new()
comment_form.show()

app.exec

comment_text = comment_form.comment_text
puts "Comment was:\n #{comment_text}"

编辑:谢谢你的回答。我只想做一个显示图片和评论的对话框,这样我就可以得到这些数据。我确实计划用qt4制作一个完整的GUI版本,但那是以后的事。

我不懂Ruby,请耐心听我说,但我在Python中广泛使用Qt

第一点是,Qt真的,真的不想被你试图使用它的方式使用。如果您正在编写某种脚本,那么Qt希望您将其交给Qt,以便它可以在感觉到以下情况时运行您的代码:

我们建议您连接清理 aboutToQuit信号的代码, 而不是把它放在你的 应用程序的主要功能是 在一些平台上 QCoreApplication::exec调用可能不可用 返回

使用Qt时,您几乎必须进行事件驱动编程,并让它控制程序流/主循环

如果您真的想要一些显示GUI输入框的实用工具,并打印用户输入到控制台的任何内容,请考虑将PATH直接放在连接到文本框的任何函数中。然后您可以在其他控制台脚本中使用该程序的输出