Monday, January 17, 2011

Programming QtRuby (1) - Open a Window

1. Main program.

# main.rb
require 'rubygems'
require 'Qt'
require 'mainwindow.rb' 

class QtApp < Qt::Application
 
 include MainWindowModule
 
 def initialize(argv)
  super(argv)
  w = MainWindow.new
  w.show
  self.exec
 end

end

QtApp.new ARGV


2. MainWindow Module
# mainwindow.rb
require 'Qt'
module MainWindowModule

 class MainWindow < Qt::MainWindow
  def initialize
   super
   self.resize 400,300
   self.setWindowTitle 'Hello from QtRuby'
  end
 end

end


3. Run it to see the result.


1 comment:

  1. If I try and put anything into the module mainwindow, say a lineEdit or somthing small like that, I cant figure out how set the layout properly. I just get the error QWidget::setLayout: Attempting to set QLayout "" on QMainWindow "", which alread
    y has a layout

    ReplyDelete