Qt Forum

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

    Solved QTextStream support unicode?

    General and Desktop
    3
    9
    2728
    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.
    • J
      Jeronimo last edited by A Former User

      Hi i'm using qtextstream but when i write in file like:

      QFile mFile(Filename);
          if(!mFile.open(QFile::WriteOnly | QIODevice::Text | QIODevice::Append))
          {
              //error
          }
          QTextStream out(&mFile);
      
      
          out << s ;
      

      And write a symbol it doesnt write me. Support unicode?

      jsulm 2 Replies Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Jeronimo last edited by

        @Jeronimo Try to set codec using http://doc.qt.io/qt-5/qtextstream.html#setCodec as described in the documentation. And you should call setGenerateByteOrderMark(true) as described in documentation, so BOM is written into the file.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        J 1 Reply Last reply Reply Quote 1
        • V
          Vicky Sharma last edited by

          @Jeronimo
          Please clear if I am wrong, you wanted converted of 's' to a symbol or write only 's' in the file?

          1 Reply Last reply Reply Quote 2
          • jsulm
            jsulm Lifetime Qt Champion @Jeronimo last edited by

            @Jeronimo Can you please explain better what happens?
            What symbols do you want to write and what is written?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 1
            • jsulm
              jsulm Lifetime Qt Champion @Jeronimo last edited by

              @Jeronimo If you read documentation (http://doc.qt.io/qt-5/qtextstream.html) you will find:
              "Internally, QTextStream uses a Unicode based buffer, and QTextCodec is used by QTextStream to automatically support different character sets. By default, QTextCodec::codecForLocale() is used for reading and writing, but you can also set the codec by calling setCodec(). Automatic Unicode detection is also supported. When this feature is enabled (the default behavior), QTextStream will detect the UTF-16 or the UTF-32 BOM (Byte Order Mark) and switch to the appropriate UTF codec when reading. QTextStream does not write a BOM by default, but you can enable this by calling setGenerateByteOrderMark(true). When QTextStream operates on a QString directly, the codec is disabled."
              So, yes it supports Unicode.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              J 2 Replies Last reply Reply Quote 0
              • J
                Jeronimo @jsulm last edited by Jeronimo

                @jsulm But why when i write like in arabic show me interrogation ??

                I'm doing this:

                void Write(QString Filename, QString s)
                {
                    QFile mFile(Filename);
                    if(!mFile.open(QFile::WriteOnly | QIODevice::Text | QIODevice::Append))
                    {
                        //error
                    }
                    QTextStream out(&mFile);
                
                
                    out << s ;
                    mFile.flush();
                    mFile.close();
                
                }
                
                Write("hola","ي")
                

                But all time show me interrogations like ????
                This only happen me with languages like arabic and russian other's not like english but idont know why take this error.

                jsulm 1 Reply Last reply Reply Quote 0
                • J
                  Jeronimo @jsulm last edited by

                  @jsulm this happen to with qdebug i can write in other language like russian etc.

                  1 Reply Last reply Reply Quote 0
                  • jsulm
                    jsulm Lifetime Qt Champion @Jeronimo last edited by

                    @Jeronimo Try to set codec using http://doc.qt.io/qt-5/qtextstream.html#setCodec as described in the documentation. And you should call setGenerateByteOrderMark(true) as described in documentation, so BOM is written into the file.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    J 1 Reply Last reply Reply Quote 1
                    • J
                      Jeronimo @jsulm last edited by

                      @jsulm works fine thxx..!!

                      jsulm 1 Reply Last reply Reply Quote 0
                      • jsulm
                        jsulm Lifetime Qt Champion @Jeronimo last edited by

                        @Jeronimo Unicode can be tricky compared to ASCII :-)

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

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