Friday, September 4, 2009

Pros and Cons of "Yet another UI File loading"

In last entry, I only introduced sample code of "Yet another UI File loading". In this post, I will write pros and cons of it.

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'
require 'rexml/document'


module Qt
class MainWindow
# override closeEvent method
def closeEvent event
puts ?a * 8
end do
window = Qt.load_ruby_from_ui(
When close the window:
This UI loading uses Kernel#eval, This method is slowly. Especially from Ruby 1.9, Kernel#eval becomes slower despite many methods become faster.

No comments:

Post a Comment