views:

11

answers:

1

I think this problem is best described in code. I'm sure the solution is close, I just haven't been able to find it. I've been looking over the Qt4 api as well as doing tutorials. Here is my code so far:

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}"

EDIT: Thanks for that answer integer. All I want done is a dialog box showing a picture and comment so I can get that data. I do plan on making a full GUI version with qt4, but that's for later.

A: 

I don't know Ruby, so bear with me, but I use Qt extensively in Python.

First point is that Qt really, really doesn't want to be used the way you're trying to use it. If you're making some sort of script, then Qt wants you to give it to Qt so it can run your code when it feels like:

We recommend that you connect clean-up code to the aboutToQuit() signal, instead of putting it in your application's main() function because on some platforms the QCoreApplication::exec() call may not return.

Working with Qt you pretty much have to do event-driven programming and give it control of your program flow / main loop.

If you really just want some "utility" that shows some GUI input box and prints whatever the user inputs to console, consider putting the puts directly in whatever function you connected to the text box. Then you can use that program's output in other console scripts.

integer