Pros
The most advantage is that Qt event model is able to be overridden with method re-definition in Ruby's open class.
Why am I decide to create this sample, it's for this article: "Overriding methods without subclassing". In this article, The reason was described by Richard that event method definition by Ruby's open class is invalid for overriding Qt's event model. In a nutshell, qtuitools deals C++ class, not Ruby class.
On the other hand, the output of rbuic4 is a ruby class. It can re-define event method with QtRuby's way, but it needs to saving output as a file: a little redundant. So I cherry-pick the nice things of both approaches, it's the sample code. And I also posted to the article(fortunately, they found another solution).
For example, the example below succeeds:
require 'Qt4'When close the window:
require 'rexml/document'
...
module Qt
class MainWindow
# override closeEvent method
def closeEvent event
puts ?a * 8
super
end
end
end
Qt::Application.new(ARGV) do
window = Qt.load_ruby_from_ui(
'/opt/qtsdk-2009.03/qt/examples/widgets/stylesheet/layouts/default.ui',
'/opt/ruby-1.9.1/bin/rbuic4')
window.show
exec
end
aaaaaaaaCons
This UI loading uses Kernel#eval, This method is slowly. Especially from Ruby 1.9, Kernel#eval becomes slower despite many methods become faster.
1 comment:
dang
Post a Comment