Results 1 to 4 of 4

Thread: QXmlStreamWriter UTF-16 Problem

  1. #1
    Join Date
    Apr 2009
    Posts
    11
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QXmlStreamWriter UTF-16 Problem

    Heho,

    I have a problem with the QXmlStreamWriter class. When using UTF-16 encoding garbage characters will appear in my XML document.

    Qt Code:
    1. QXmlStreamWriter xml;
    2. xml.setDevice(&file);
    3. // here is the problem
    4. xml.setCodec(QTextCodec::codecForName("utf16"));
    5. xml.setAutoFormatting(true);
    6. xml.setAutoFormattingIndent(2);
    7.  
    8. xml.writeStartDocument();
    9.  
    10. xml.writeDTD("<!DOCTYPE backup>");
    11. xml.writeStartElement("Backup");
    12. xml.writeAttribute("version", "1.0");
    13.  
    14. xml.writeStartElement("Task");
    15. xml.writeAttribute("name", "MyName");
    16. xml.writeTextElement("Description", "My short description");
    17. xml.writeEndElement(); // Task
    18.  
    19. xml.writeEndElement();
    20. xml.writeEndDocument();
    To copy to clipboard, switch view to plain text mode 

    Output:
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-16"?>਍㰀℀䐀伀䌀吀夀倀䔀 戀愀挀欀甀瀀㸀ഀ
    2. <Backup version="1.0">਍  㰀吀愀猀欀 渀愀洀攀㴀∀䴀礀 昀椀爀猀琀 戀愀挀欀甀瀀∀㸀ഀ
    3. <Description>My short description</Description>਍    㰀䔀渀愀戀氀攀搀㸀琀爀甀攀㰀⼀䔀渀愀戀氀攀搀㸀ഀ
    4. etc....
    To copy to clipboard, switch view to plain text mode 

    Do you have any idea? Thank you very much for your help.

    Best regards,


    Loco

  2. #2
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QXmlStreamWriter UTF-16 Problem

    Qt 4.6.0 + VS2008 + windows Xp sp3

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-16"?>
    2. <!DOCTYPE backup>
    3. <Backup version="1.0">
    4. <Task name="MyName">
    5. <Description>My short description</Description>
    6. </Task>
    7. </Backup>
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. fffe 3c00 3f00 7800 6d00 6c00 2000 7600
    2. 6500 7200 7300 6900 6f00 6e00 3d00 2200
    3. 3100 2e00 3000 2200 2000 6500 6e00 6300
    4. 6f00 6400 6900 6e00 6700 3d00 2200 5500
    5. 5400 4600 2d00 3100 3600 2200 3f00 3e00
    6. 0a00 3c00 2100 4400 4f00 4300 5400 5900
    7. 5000 4500 2000 6200 6100 6300 6b00 7500
    8. 7000 3e00 0a00 3c00 4200 6100 6300 6b00
    9. 7500 7000 2000 7600 6500 7200 7300 6900
    10. 6f00 6e00 3d00 2200 3100 2e00 3000 2200
    11. 3e00 0a00 2000 2000 3c00 5400 6100 7300
    12. 6b00 2000 6e00 6100 6d00 6500 3d00 2200
    13. 4d00 7900 4e00 6100 6d00 6500 2200 3e00
    14. 0a00 2000 2000 2000 2000 3c00 4400 6500
    15. 7300 6300 7200 6900 7000 7400 6900 6f00
    16. 6e00 3e00 4d00 7900 2000 7300 6800 6f00
    17. 7200 7400 2000 6400 6500 7300 6300 7200
    18. 6900 7000 7400 6900 6f00 6e00 3c00 2f00
    19. 4400 6500 7300 6300 7200 6900 7000 7400
    20. 6900 6f00 6e00 3e00 0a00 2000 2000 3c00
    21. 2f00 5400 6100 7300 6b00 3e00 0a00 3c00
    22. 2f00 4200 6100 6300 6b00 7500 7000 3e00
    23. 0a00 0a
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to dbzhang800 for this useful post:

    27Loco (7th July 2010)

  4. #3
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QXmlStreamWriter UTF-16 Problem

    OK, I know

    you using windows and your file opened with QIODevice::Text, So

    "0a00 ..." ==> "0d0a 00..."

    fffe 3c00 3f00 7800 6d00 6c00 2000 7600
    6500 7200 7300 6900 6f00 6e00 3d00 2200
    3100 2e00 3000 2200 2000 6500 6e00 6300
    6f00 6400 6900 6e00 6700 3d00 2200 5500
    5400 4600 2d00 3100 3600 2200 3f00 3e00
    0d0a 003c 0021 0044 004f 0043 0054 0059
    0050 0045 0020 0062 0061 0063 006b 0075
    0070 003e 000d 0a00
    3c00 4200 6100 6300
    6b00 7500 7000 2000 7600 6500 7200 7300
    6900 6f00 6e00 3d00 2200 3100 2e00 3000
    2200 3e00 0d0a 0020 0020 003c 0054 0061
    0073 006b 0020 006e 0061 006d 0065 003d
    0022 004d 0079 004e 0061 006d 0065 0022
    003e 000d 0a00 2000 2000 2000 2000 3c00
    4400 6500 7300 6300 7200 6900 7000 7400
    6900 6f00 6e00 3e00 4d00 7900 2000 7300
    6800 6f00 7200 7400 2000 6400 6500 7300
    6300 7200 6900 7000 7400 6900 6f00 6e00
    3c00 2f00 4400 6500 7300 6300 7200 6900
    7000 7400 6900 6f00 6e00 3e00 0d0a 0020
    0020 003c 002f 0054 0061 0073 006b 003e
    000d 0a00 3c00 2f00 4200 6100 6300 6b00
    7500 7000 3e00 0d0a 000a
    Last edited by dbzhang800; 7th July 2010 at 02:47.

  5. The following user says thank you to dbzhang800 for this useful post:

    27Loco (7th July 2010)

  6. #4
    Join Date
    Apr 2009
    Posts
    11
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: QXmlStreamWriter UTF-16 Problem

    You are right. I used QIODevice::Text. This was the problem. Thank you very much for the solution .

Similar Threads

  1. Readable Xml with QXmlStreamWriter
    By jano_alex_es in forum Newbie
    Replies: 8
    Last Post: 26th August 2009, 11:53
  2. Replies: 2
    Last Post: 26th August 2009, 10:18
  3. Adding elements with QXmlStreamWriter
    By hazardpeter in forum Newbie
    Replies: 4
    Last Post: 22nd August 2009, 12:45
  4. QXmlStreamWriter and attribute namespaces
    By TomasC in forum Qt Programming
    Replies: 0
    Last Post: 11th December 2008, 06:11
  5. Blank file using QXmlStreamWriter
    By sgmurphy19 in forum Qt Programming
    Replies: 4
    Last Post: 14th November 2007, 20:45

Tags for this Thread

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.