Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] XML coded in UTF-8 on Linux

    General and Desktop
    4
    7
    3532
    Loading More Posts
    • 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
      adam.bogocz last edited by

      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 Reply Quote 0
      • T
        TheDestroyer last edited by

        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 Reply Quote 0
        • A
          adam.bogocz last edited by

          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 Reply Quote 0
          • A
            andre last edited by

            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 Reply Quote 0
            • G
              goetz last edited by

              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 Reply Quote 0
              • A
                adam.bogocz last edited by

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

                1 Reply Last reply Reply Quote 0
                • G
                  goetz last edited by

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

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

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post