[Qt-jambi-interest] codecForTr
Eskil Abrahamsen Blomfeldt
eblomfel at trolltech.com
Mon Apr 7 16:03:25 CEST 2008
Hi, Tomasz.
Tomasz 'Trog' Welman wrote:
> I've just one problem.
> QTextCodec.codecForLocale() returns "System", which is... annoying,
> because when I run an application (having utf-8 as my base encoding),
> which reads iso2 files into string, converts this string to unicode,
> and then (from unicode) to target encoding (which is the base encoding of
> the wmsystem, in my case KDE & utf-8) the string are displayed
> incorrectly
> in gui objects like QLineEdit.
If your string is encoded in unicode, it should display correctly in
QLineEdit without any further change to the encoding. Does this fail?
In your case I would read the 8-bit encoded files into e.g. a QByteArray
to avoid the implicit conversion to unicode, convert the byte array to
unicode using QTextCodec and then setting this string directly on the
QLineEdit. Since Qt Jambi handles all the GUI in your application,
including the text, and Qt Jambi is inherently unicode-based, you should
not need to worry about the 8-bit encoding of your target platform in
the GUI elements.
When writing files to the disk, do it the other way around: Take the
unicode string, convert it to your selected encoding and write the
resulting QByteArray to the file.
I've attached a little example of what I mean. The test.txt file is
encoded in UTF-8, and I am using a QTextCodec to decode it. When running
the application you should be able to edit an actual line in the line
edit (as nature intended.)
Please correct me if I misunderstood something.
-- Eskil
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.txt
Url: http://lists.trolltech.com/pipermail/qt-jambi-interest/attachments/20080407/dbb073ae/attachment.txt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ReadTextFile.java
Type: text/java
Size: 665 bytes
Desc: not available
Url : http://lists.trolltech.com/pipermail/qt-jambi-interest/attachments/20080407/dbb073ae/attachment.bin
More information about the Qt-jambi-interest
mailing list