[Kde-bindings] weird behaviour of some classes' #text method in korundum
Stefano Crocco
stefano.crocco at alice.it
Mon Jan 31 09:29:18 UTC 2011
Hello to everyone,
I just found out what I consider a bug. There are some classes with a #text
method which behaves strangely. Take for example the following code
require 'Qt4'
app = Qt::Application.new []
w = Qt::Label.new; p w.text # => nil
w.text = ''; p w.text # => nil
w.text = 'xyz'; p w.text # => "xyz"
w.text = ''; p w.text # => ""
It seems that Qt::Label#text returns nil until I set the text to a non-empty
string; after that #text correctly returns a string even after I set the text
back to '' (nothing changes if I pass an empty string as first argument to the
constructor).
Other classes which behave this way are Qt::PushButton, Qt::CheckBox and
KTextEditor::Document (there may be others, too. I didn't do an exhaustive
search). Regading KTextEditor::Document, it's not only its #text method which
behaves this way, but also #line. This means that, given the following text:
line0
line2
line4
the following snippet of code produces what I consider a very surprising
result:
0.upto(4){|i| p doc.line(i)}
=> "line0"
=> nil
=> "line2"
=> nil
=> "line4"
The output I'd expect, of course, is:
"line0"
""
"line2"
""
"line4"
I could understand if #line returned nil when its argument is greater than the
number of lines in the document, but I think it's wrong returning nil for an
empty line.
Is the behaviour I described expected, or is it a bug? If it's not a bug,
could anyone tell me which are the reasons behind it?
Thanks in advance
Stefano
More information about the Kde-bindings
mailing list