Results 1 to 5 of 5

Thread: QtXml and special characters

  1. #1
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QtXml and special characters

    Hello,

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

    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:
    Qt Code:
    1. void parseSongElement(const QDomElement &element)
    2. {
    3. int id = element.attribute("id").toInt();
    4. Song* song = new Song(id);
    5. song->path = element.attribute("path");
    6. song->info.title = element.attribute("title");
    7. song->info.artist = element.attribute("artist");
    8. song->info.album = element.attribute("album");
    9. currentPlaylist->append(song);
    10. }
    To copy to clipboard, switch view to plain text mode 
    I have tried using element.attribute("path").toAscii() but that doesn't work either...

    Thanks in advance,
    Gillis
    Last edited by supergillis; 27th September 2008 at 18:13.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtXml and special characters

    What is the type of song->info.title? Does this XML contain information about encoding?

  3. #3
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtXml and special characters

    Quote Originally Posted by jacek View Post
    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...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtXml and special characters

    How do you read the data into QDomDocument?

  5. #5
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtXml and special characters

    Quote Originally Posted by jacek View Post
    How do you read the data into QDomDocument?
    This is how I load it:
    Qt Code:
    1. QDomDocument domDocument;
    2. QFile device("library.xml");
    3. if(!device.open(QFile::ReadOnly))
    4. {
    5. QMessageBox::warning(NULL, "Library", QString("Unable to load the library. Making a new one..."));
    6. return false;
    7. }
    8. QString errorStr;
    9. int errorLine;
    10. int errorColumn;
    11. if(!domDocument.setContent(&device, true, &errorStr, &errorLine, &errorColumn))
    12. {
    13. QMessageBox::information(NULL, QString("Library"), QString("Parse error at line %1, column %2:\n%3").arg(errorLine).arg(errorColumn).arg(errorStr));
    14. return false;
    15. }
    To copy to clipboard, switch view to plain text mode 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.