ryanmelt / qtbindings

An easy to install gem version of the Ruby bindings to Qt
http://github.com/ryanmelt/qtbindings
Other
340 stars 63 forks source link

combox currentText returns ASCII-8BIT #135

Closed stkrys closed 8 years ago

stkrys commented 8 years ago

Hello,

when I write code like this with ruby 2.2.3:

`Qt::Application.new(ARGV)

cmb = Qt::ComboBox.new

item_str = Qt::QString::fromUtf8("öüäß")

item_str = "öüäß".encode("UTF-8") cmb.addItem(item_str, Qt::Variant.new(1))

cmb.setCurrentIndex(0)

puts "#{cmb.count}" puts "#{cmb.currentText} #{cmb.currentText.encoding} --- #{item_str.encoding}"# puts "#{cmb.currentText == item_str}" puts "#{cmb.currentText.force_encoding('UTF-8') == item_str}"`

=>

1 öüäß ASCII-8BIT --- UTF-8 false true

currentText returns ASCII-8BIT which cant be compared with the original Text. Is there something I missed or some kind of global setting/workaround. So I dont have to use force_encoding everytime?

Thank you in advance

jmthomas commented 8 years ago

I've done no work with UTF-8 encoding or any other encoding in Qt. When you call currentText we're just calling back to the underlying Qt method. However I'm not surprised that by converting it back to Ruby we lose the encoding. Qt::Application has a translate method that calls the internal Qt translate method and forces the encoding to UTF-8. I'm not sure if that helps or if you're basically just calling another another method to get what you want.