Qtruby overrides "to_s" depending on user's LOCALES

Hi, is it an appropiate list for asking about QtRuby?

Note the following issue:


~# export LANG=es_ES.UTF-8

~# irb1.8

irb> require “Qt4”

irb> num = 1.1
irb> puts num
1.1

irb> app = Qt::Application.new(ARGV)
#<Qt::Application:0x7f48392e6a70 objectName=“irb1.8”>

irb> puts num
1,1

As you can see, after creating a Qt::Application instance, FixNum#to_s
has
been overriden and prints the number in a format depending on user’s
LOCALES
(in Spanish 1.1 is displayed as 1,1).

I’ve critical issues with it because I use some external libraries as
httpclient which creates wrong HTTP request after creating a instace of
Qt::Application:

GET /index.html HTTP/1,1 <— Note 1,1 !!!

Is there any way to disable this behaviour in QtRuby? any workaround?
Thanks a lot.

On Sunday 02 August 2009, Iñaki Baz C. wrote:

|
|
|
|Is there any way to disable this behaviour in QtRuby? any workaround?
|Thanks a lot.
|

You can certainly post QtRuby related questions here, but probably
you’ll get
more answers using the qtruby mailing list [email protected] or the
qtruby
forum: http://rubyforge.org/forum/forum.php?forum_id=723.

Regarding your question, you can find an explaination of why this
happens (and
some workarounds) in this thread of the qtruby forum:
http://rubyforge.org/forum/message.php?msg_id=67059

If you only want a quick solution, you can do the following: create a
Qt::Locale object based on the C locale using Qt::Locale.c, sets its
number_options property to Qt::Locale::OmitGroupSeparator and use its
to_string method to create the string. Something like this:

x = 1234.567
l = Qt::Locale.c
l.number_options = Qt::Locale::OmitGroupSeparator
puts l.to_string(x)

Without changing the number_options property, you’ll get a number
separator in
the string (in the example, you’d get the string “1,234.567”).

I hope this helps

Stefano

El Domingo, 2 de Agosto de 2009, Iñaki Baz C. escribió:

As you can see, after creating a Qt::Application instance, FixNum#to_s has
been overriden and prints the number in a format depending on user’s
LOCALES (in Spanish 1.1 is displayed as 1,1).

ops, a related thread with no happy final:
http://rubyforge.org/forum/forum.php?thread_id=32460&forum_id=723

El Domingo, 2 de Agosto de 2009, Stefano C. escribió:

Regarding your question, you can find an explaination of why this happens
(and some workarounds) in this thread of the qtruby forum:
http://rubyforge.org/forum/message.php?msg_id=67059

Yes, after sending the mail I found the same thread :slight_smile:

If you only want a quick solution, you can do the following: create a
Qt::Locale object based on the C locale using Qt::Locale.c, sets its
number_options property to Qt::Locale::OmitGroupSeparator and use its
to_string method to create the string. Something like this:

x = 1234.567
l = Qt::Locale.c
l.number_options = Qt::Locale::OmitGroupSeparator
puts l.to_string(x)

But this is not valid to me since I use 3rd party libraries (as
httpclient
which suffers this issue when generating a HTTP request).

Then, I assume that I must change the locales globally but this would
break
the Qt translations and so… :frowning:

Dark issue…

Thanks a lot.

El Domingo, 2 de Agosto de 2009, Stefano C. escribió:

l = Qt::Locale.c
l.number_options = Qt::Locale::OmitGroupSeparator
l.to_string(self)

end
end
x = 1234.567
puts x

Thanks, I already saw this solution in the RubyForge thread. However I’m
afraid of what could happen if this issue affects to more Ruby classes
than
just Float. But it seems the bets solution (even if it’s obviously a
painful
hack XD).

Thanks a lot.

On Sunday 02 August 2009, Iñaki Baz C. wrote:

|> to_string method to create the string. Something like this:
|>
|> x = 1234.567
|> l = Qt::Locale.c
|> l.number_options = Qt::Locale::OmitGroupSeparator
|> puts l.to_string(x)
|
|But this is not valid to me since I use 3rd party libraries (as httpclient
|which suffers this issue when generating a HTTP request).

You can try redefining the Float#to_s method after creating the
application,
using the code I suggested inside it. This works in a simple example,
but I’m
not sure what would happen in a real situation.

require ‘Qt4’

a = Qt::Application.new []

class Float
def to_s
l = Qt::Locale.c
l.number_options = Qt::Locale::OmitGroupSeparator
l.to_string(self)
end
end
x = 1234.567
puts x

Stefano

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs