[Qt-interest] Accented characters and QDom in Windows
Ellen Kestrel
dragonflykes at gmail.com
Thu Aug 20 19:11:13 CEST 2009
Ah, good - how do I indicate encodings in the XML - is it specified with the
document type? I have just been putting strings meant for humans to read
there, as the examples use things like "mydocument" and "MyML". This is the
first time I've really played with XML, actually.
Reading XML:
QDomDocument doc ("ConlangML");
QFile file (filename + ".cdic");
if (!file.open (QFile::ReadOnly)) {
QMessageBox::warning (this, "", "Cannot read file.");
return;
}
if (!doc.setContent (&file)) {
QMessageBox::warning (this, "", "Cannot read XML.");
file.close ();
return;
}
file.close ();
Writing XML:
QFile file (filename + ".cdic");
QTextStream out (&file);
if (!file.open (QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning (this, "", "Cannot write file.");
return;
}
out << doc.toString ();
file.close ();
Or is it to do with the QTextStream?
EK
On Thu, Aug 20, 2009 at 10:50 AM, Andreas Pakulat <apaku at gmx.de> wrote:
> On 20.08.09 10:33:04, Ellen Kestrel wrote:
> > I compiled an application I wrote in linux under Windows the other day,
> and
> > there seems to be a problem with the QDom classes I'm using to read and
> > write files and accented characters. If I enter in (say) "á" into the
> > program, save it to a file (where it still appears as "á") and then load
> it
> > back into the program, the program now displays it as a box, and the
> > text-parsing parts of the program do not recognize it as "á". If I
> replace
> > the "á" in the XML file with the appropriate entity (in the form of
> &#XXX;)
> > it reads it just fine. This problem does not occur in linux.
>
> Sounds like you've got a pretty nice encoding issue there. That is, your
> XML gets saved to disk in encoding A, but when you read it back in you're
> using encoding B. Luckily xml files contain an encoding tag (or default to
> utf-8), so this should be easily fixable. To help you I suggest to show us
> the code that reads the xml (from the point where you have a filename in a
> string to the point where the dom-document is created) and the code that
> saves it to a file (from the point where populating the dom is done until
> the file is closed).
>
> Andreas
>
> --
> You like to form new friendships and make new acquaintances.
> _______________________________________________
> 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/20090820/cb3376f4/attachment.html
More information about the Qt-interest-old
mailing list