Monday, March 30, 2009


Command rbuic4 is a generator from Qt Designer's XML file that defines user interface to ruby script. Qt 4.5 SDK contains some UI demos and UI examples. Let's try to generate ruby scripts from these UI files with below ruby codes:
qt_dir = '/opt/qtsdk-2009.01/qt'
target_dir = '/path/to/target_dir'
`find #{qt_dir}/demos #{qt_dir}/examples -name '*.ui'`.split.each do |ui_file|
  basename = File.basename ui_file, '.ui'
  `/opt/ruby-1.9.1/bin/rbuic4 #{ui_file} -x -o #{target_dir}/#{basename}.rb`

Ruby script files are generated, but these files are written in non-rubyish style (in addition, less object-oriented style).

For example, launch one of generated script, default.rb.
>/opt/ruby-1.9.1/bin/ruby default.rb

No comments:

Post a Comment