PDA

View Full Version : QtXml and special characters



supergillis
27th September 2008, 16:27
Hello,

I'm saving a QList of songs into an XML. That goes well but the loading doesn't work out very well :confused:

When I save for example the song "Björk - It's Oh So Quiet.mp3" you get this in the XML file:
<song title="It's Oh So Quiet" path="C:\Documents and Settings\Gillis\Mijn documenten\Mijn muziek\Apart\Björk - It's Oh So Quiet.mp3" artist="Björk" album="It's Oh So Quiet" id="66" />.

When I try to load the path or the artist the 'ö' changes in a '?' or other things...

This is how I load the attributes:

void parseSongElement(const QDomElement &element)
{
int id = element.attribute("id").toInt();
Song* song = new Song(id);
song->path = element.attribute("path");
song->info.title = element.attribute("title");
song->info.artist = element.attribute("artist");
song->info.album = element.attribute("album");
currentPlaylist->append(song);
}
I have tried using element.attribute("path").toAscii() but that doesn't work either...

Thanks in advance,
Gillis

jacek
27th September 2008, 23:06
What is the type of song->info.title? Does this XML contain information about encoding?

supergillis
28th September 2008, 22:25
What is the type of song->info.title? Does this XML contain information about encoding?

song->info.title is a QString and the XML hasn't got ecoding information...

jacek
28th September 2008, 22:57
How do you read the data into QDomDocument?

supergillis
29th September 2008, 18:44
How do you read the data into QDomDocument?
This is how I load it:

QDomDocument domDocument;
QFile device("library.xml");
if(!device.open(QFile::ReadOnly))
{
QMessageBox::warning(NULL, "Library", QString("Unable to load the library. Making a new one..."));
return false;
}
QString errorStr;
int errorLine;
int errorColumn;
if(!domDocument.setContent(&device, true, &errorStr, &errorLine, &errorColumn))
{
QMessageBox::information(NULL, QString("Library"), QString("Parse error at line %1, column %2:\n%3").arg(errorLine).arg(errorColumn).arg(errorStr));
return false;
}