[Qt-interest] Accented characters and QDom in Windows

Ellen Kestrel dragonflykes at gmail.com
Fri Aug 21 10:02:51 CEST 2009


Just to be clear, here, I am not passing QStrings to the fromXXX functions.
I don't think I've ever used those functions for anything other than string
literals.  The characters that cannot be input into the line edits are (that
I've noticed) slightly less common IPA characters (ɾ ʃ ʧ ʤ, for example).

Another strange thing I have noticed now, which might be relevant here, is
that the files containing accented and special characters that were written
to disc under linux (in Utf-8) display the special characters as "á" and
the like in Windows, which looks like some kind of encoding mismatch.  I
vaguely remember seeing this happen a long time ago when I tried to get a
QLabel to display special characters that were entered into the source code
without doing toUtf8 () on them.  The Windows app is able to parse those
files just fine, even when reading them in via QTextStream.  I'm viewing
these files with gvim for Windows.

I did compile with the no-casting-to/from-ascii defines, and it only causes
a few errors from setting the text of QPushButtons on initialization with a
hardcoded string that contains only standard, unaccented characters.

EK

On Fri, Aug 21, 2009 at 1:45 AM, Thiago Macieira <
thiago.macieira at trolltech.com> wrote:

> Ellen Kestrel wrote:
> >The issue with the special characters not showing isn't (necessarily)
> >related to inputs from files or hard-coded strings; if the user types
> > (or copies and pastes) the character into a line edit widget or
> > similar, it shows up as a line or a box in the line edit.
>
> Hi Ellen
>
> There's something wrong with your code. I urge you to compile with
> QT_NO_CAST_TO_ASCII and QT_NO_CAST_FROM_ASCII so you can find it.
>
> When the user pastes something into the line edit, he/she can only paste
> valid Unicode strings. Therefore, there's nothing mis-encoded. If
> something shows up mis-encoded, it's because your program corrupted it.
>
> The only sources of bad encoding are conversion from 8-bit into Unicode.
> They can be either the source file's hard-coded strings, or not properly
> setting the encoding of a given file. Or, which is your case, mishandling
> of already QString objects.
>
> > Also, the
> > fromXXX functions all take character arrays, so while they do work with
> > hard-coded text, the user input is already in QString form by the time
> > I get it.
>
> That's wrong. Never use fromXXX on something that comes from QString. For
> example, the following code will likely produce bad data:
>
>        QString str = QString::fromUtf8(lineedit.text());
>
> If you add the macros I mentioned, this code will not compile. You'll
> notice that, to make it compile again, you have to either fix the error
> (which is the recommended alternative :-) ) or make the error more
> explicit:
>
>        QString str = QString::fromUtf8(lineedit.text().toAscii()));
>
> As you can see above, you take some QString, encode it to ASCII[*], then
> decode it as UTF-8. That can't be right. The recommended alternative is to
> simply do:
>
>        QString str = lineedit.text();
>
> [*] "ASCII" is a misnomer here; it's actually what Qt calls the "codec for
> C strings", that is, the encoding that your source file should be. By
> default, that's Latin 1.
>
> --
> Thiago Macieira - thiago.macieira (AT) nokia.com
>  Senior Product Manager - Nokia, Qt Development Frameworks
>     Sandakerveien 116, NO-0402 Oslo, Norway
>
> Qt Developer Days 2009 | Registration Now Open!
> Munich, Germany: Oct 12 - 14     San Francisco, California: Nov 2 - 4
>      http://qt.nokia.com/qtdevdays2009
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090821/f5afd6ac/attachment.html 


More information about the Qt-interest-old mailing list