Results 1 to 9 of 9

Thread: XML resource is garbled?

  1. #1
    Join Date
    Dec 2009
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default XML resource is garbled?

    I've added a .rc file with an xml document containing a list of unit conversions. Here's some code:

    Qt Code:
    1. QFile rc(":/data/units.xml");
    2. if(!rc.open(QIODevice::ReadOnly))
    3. {
    4. qDebug() << "File Error: " << rc.errorString();
    5. return;
    6. }
    7. QTextStream stream( &rc );
    8. qDebug() << "Start doc:";
    9. qDebug() << stream.readAll();
    10. qDebug() << "End doc";
    11. rc.close();
    To copy to clipboard, switch view to plain text mode 

    After a certain point, a few random characters come out and the stream ends prematurely.
    Start doc:
    "<unitlist>

    <!-- couple dozen lines of xml i wrote-->

    <utype name="ti‘Ð’Ëi€End doc

    Any idea what could be causing this?

  2. #2
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: XML resource is garbled?

    To avoid errors, specify the XML encoding, or save XML files as Unicode.

  3. #3
    Join Date
    Dec 2009
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML resource is garbled?

    I added <?xml version="1.0" encoding="utf-8"?> and explicitly saved in UTF-8 but the problem persists. It fails consistently in the same location. I've given the file. If you open it in a browser it gives the same complaint as Qt. So there is a problem with the file and not the resource. Is the encoding still messed up?

    I also have some png resources, which display fine, but they're smaller than this file. It seems kind of weird that a 3.7KB file would be too much, but is there a limit on the size of a resource?

    You might have to rename the attachment to units.xml, I don't know why the website added a period.
    Attached Files Attached Files
    Last edited by space_otter; 20th June 2010 at 04:00.

  4. #4
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: XML resource is garbled?

    Hi,

    Top level item is missing in your file. In the below example "property" is the top level item. You cannot have multiple top-level items as in your file.

    eg.,

    <?xml version="1.0" encoding="utf-8"?>
    <property>
    <unitlist>
    <utype name="mass">
    </unitlist>
    <powers>
    <powers>
    .
    .
    .
    </property>

  5. #5
    Join Date
    Dec 2009
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML resource is garbled?

    Thanks, I don't really know xml that well that fixes the parsing problem. But I still don't understand why the readout still ends prematurely, or why the commented part also ends too early.

  6. #6
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: XML resource is garbled?

    Hi,

    Reading your units.xml just works fine for me (the file is not well formed-your sample). Did you use notepad to edit the xml stuff ? Did you edit the items ?. Something may be wrong in your function or just before calling your function ?!.

  7. #7
    Join Date
    Dec 2009
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML resource is garbled?

    I used notepad++. The file is in a resource and I access it with ":/data/units.xml" and that might have something to do with it.

  8. #8
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: XML resource is garbled?

    Try reading line by line and see if that works !~

  9. #9
    Join Date
    Dec 2009
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML resource is garbled?

    Ah! thanks. Looks like readAll can't be trusted?

Similar Threads

  1. Replies: 8
    Last Post: 7th November 2012, 19:20
  2. MySQL database ,Garbled
    By weixj2003ld in forum Qt Programming
    Replies: 7
    Last Post: 9th June 2009, 14:24
  3. QLocale/Resource
    By coderbob in forum Newbie
    Replies: 4
    Last Post: 21st November 2007, 20:51
  4. Garbled fonts in QGraphicsView
    By StevenB in forum Qt Programming
    Replies: 6
    Last Post: 30th September 2007, 07:56
  5. Resource file in a lib
    By Rodrigo in forum Qt Programming
    Replies: 4
    Last Post: 25th June 2007, 15:22

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
  •  
Qt is a trademark of The Qt Company.