Results 1 to 4 of 4

Thread: Reading Japanese chars from QNetworkReply

  1. #1
    Join Date
    Mar 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Reading Japanese chars from QNetworkReply

    I've written a feed parser, however i'm having trouble reading japanese characters, I.E
    Antidoteæ¼¢å*—
    shows up as
    Antidoteæ¼¢å*—
    Which is clearly wrong, it seems that i'm not setting my header correctly
    Qt Code:
    1. {
    2. QUrl url("http://zfgc.com/forum/index.php?action=.xml");
    3.  
    4. QNetworkRequest request(url);
    5. request.setRawHeader( "User-Agent", "Mozilla/5.0 (X11; U; Linux i686 (x86_64); "
    6. "en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1" );
    7. request.setRawHeader( "charset", "utf-8" );
    8. request.setRawHeader( "Connection", "keep-alive" );
    9. m_networkAccess->get(request);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Any help would be greatly appreciated thanks.

    I should probably post my DOM parser as well just incase the issue is there
    Qt Code:
    1. QTextStream xmlData(m_data);
    2. xmlData.setCodec("UTF-8");
    3. xmlData.setAutoDetectUnicode(true);
    4. doc.implementation().setInvalidDataPolicy(QDomImplementation::AcceptInvalidChars);
    5. doc.setContent(xmlData.readAll());
    6.  
    7.  
    8. QDomNodeList nodeList = doc.documentElement().elementsByTagName("recent-post");
    9.  
    10. for (int i = 0; i < nodeList.count(); i++)
    11. {
    12. qint32 id = -1;
    13. QPair<QString, QPair<QString, QString> > pair;
    14.  
    15. QDomElement el = nodeList.at(i).toElement();
    16.  
    17. QDomNode entry = el.firstChild();
    18.  
    19. while(!entry.isNull())
    20. {
    21. QDomElement eData = entry.toElement();
    22. QString tagName = eData.tagName();
    23.  
    24. if (tagName == "id" && id == -1)
    25. {
    26. id = eData.text().toInt();
    27. if (m_feedMap.contains(id) || m_pending.contains(id))
    28. id = -1;
    29. }
    30. else if (tagName == "poster" && pair.first.isEmpty())
    31. {
    32. QDomNodeList posterChildren = eData.childNodes();
    33.  
    34. for (int j = 0; j < posterChildren.count(); j++)
    35. {
    36. QDomElement child = posterChildren.at(j).toElement();
    37. if (child.tagName() == "name")
    38. {
    39. pair.first = child.text();
    40. }
    41. }
    42. }
    43. else if (tagName == "subject" && pair.second.first.isEmpty())
    44. {
    45. pair.second.first = eData.text();
    46. }
    47. else if (tagName == "link" && pair.second.second.isEmpty())
    48. {
    49. pair.second.second = eData.text();
    50. }
    51.  
    52. entry = entry.nextSibling();
    53. }
    54.  
    55. if (id != -1)
    56. {
    57. if (m_pending.count() >= 6)
    58. m_pending.erase(m_pending.begin());
    59.  
    60. if (!m_feedMap.contains(id) && !m_pending.contains(id))
    61. m_pending.insert(id, pair);
    62. }
    63. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Antidote; 25th March 2013 at 21:31.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,579
    Thanks
    13
    Thanked 1,584 Times in 1,513 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Reading Japanese chars from QNetworkReply

    There is no standard "charset" HTTP request header: try "Accept-Charset".
    The character set returned comes back in the Content-Type header: have you checked that?

    You should just feed the raw QByteArray of received data into the QDomDocument and let it worry about the encoding (specified in the xml header). No need for a QTextStream.

  3. #3
    Join Date
    Mar 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading Japanese chars from QNetworkReply

    Alright i'll give that a shot thanks

    Content-Type is "text/xml; charset=UTF-8" but the data is still incorrect
    Last edited by Antidote; 25th March 2013 at 23:08.

  4. #4
    Join Date
    Mar 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading Japanese chars from QNetworkReply

    I figured it out, I was converting text to UTF-8 unnecessarily (msg.toUtf8()) before outputting the data to my IRC tcp socket.
    Completely my fault

Similar Threads

  1. Replies: 11
    Last Post: 10th February 2011, 01:38
  2. Replies: 1
    Last Post: 10th October 2010, 00:54
  3. Japanese Text
    By kroenecker in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2009, 15:47
  4. Conversion of Unicode to Japanese
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2008, 15:35
  5. uim/Anthy Japanese Input
    By kroenecker in forum Qt Programming
    Replies: 3
    Last Post: 3rd May 2007, 05:23

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.