Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] XML coded in UTF-8 on Linux

[Solved] XML coded in UTF-8 on Linux

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adam.bogocz
    wrote on last edited by
    #1

    Hello,
    I have written app which reads XML with QXMLQuery and using XQuery recieving data. But I am fighting for 2 days with encoding. Code:

    @QFile sourceDocument( ":/xml/data.xml", this );
    sourceDocument.open( QIODevice::ReadOnly );
    m_query.bindVariable( "inputDocument", &sourceDocument );
    QByteArray outArray;
    QBuffer buffer( &outArray );

    buffer.open( QIODevice::ReadWrite );
    m_query.setQuery( query_str );
    m_query.evaluateTo( &buffer );
    QString result = QString::fromUtf8( outArray );@

    Result string contains some numbers instead of special chatacters...
    Please, can somebody tell me, how to process that UTF-8 XML ??

    Thanks,
    Adam

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TheDestroyer
      wrote on last edited by
      #2

      You're opening your file as binary, which I don't understand why, just wanted to point that out.

      Then anyway, remember that for special characters, the stand ASCII decoding doesn't apply anymore. You have to to use 2 byte characters

      http://en.m.wikipedia.org/wiki/UTF-8

      Which are supported by standard C++ with char_w and other similar containers. Please read about that. For example, if I want to save some data with Arabic language, I have to save the whole file with 2 byte decoding.

      Regards.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adam.bogocz
        wrote on last edited by
        #3

        I know that I need to use 2byte char.. I am sure that I dont need to use char_w with Qt, QString is working with UTF-16 by default.. and QFile does not mean that I am opening it as binary... I need to specify right codec for XML parser when it evaluates the query, because he messes up.. I am able to decode that XML into QString via QFile without corruption, but QXMLQuery does not support that I will pass the document as data, it wants to access the data itself.. and than it messes up encoding

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Qt already handles UTF very well. There is no need whatsoever to use char_w here.

          @adam.bogocz: I'm sorry, I don't know the answer to your actual question.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            What's the result if you evaluate to a QString directly, instead of a QByteArray?

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • A Offline
              A Offline
              adam.bogocz
              wrote on last edited by
              #6

              Hi Volker, passing QString into evaluate works well, conding is kept :) Thanks !

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                Don't forget to mark the topic as solved then, thanks!

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved