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. QTextStream support unicode?
Forum Updated to NodeBB v4.3 + New Features

QTextStream support unicode?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 3.3k 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.
  • J Offline
    J Offline
    Jeronimo
    wrote on last edited by A Former User
    #1

    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?

    jsulmJ 2 Replies Last reply
    0
    • J 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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #7

      @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
      1
      • V Offline
        V Offline
        Vicky Sharma
        wrote on last edited by
        #2

        @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
        2
        • J Jeronimo

          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?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #3

          @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
          1
          • J Jeronimo

            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?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @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
            0
            • jsulmJ jsulm

              @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.

              J Offline
              J Offline
              Jeronimo
              wrote on last edited by Jeronimo
              #5

              @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.

              jsulmJ 1 Reply Last reply
              0
              • jsulmJ jsulm

                @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.

                J Offline
                J Offline
                Jeronimo
                wrote on last edited by
                #6

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

                1 Reply Last reply
                0
                • J 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.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @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
                  1
                  • jsulmJ jsulm

                    @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.

                    J Offline
                    J Offline
                    Jeronimo
                    wrote on last edited by
                    #8

                    @jsulm works fine thxx..!!

                    jsulmJ 1 Reply Last reply
                    0
                    • J Jeronimo

                      @jsulm works fine thxx..!!

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

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

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

                      1 Reply Last reply
                      1

                      • Login

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