Qt Forum

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

    Unsolved How to fix garbled text from QSqlQuery

    General and Desktop
    3
    4
    801
    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.
    • LeonSu
      LeonSu last edited by

      Hello every one
      My OS is Ubuntu 16.04.
      The codec includes C C.UTF-8 en_US.utf8 zh_CN.utf8 zh_TW zh_TW.big5 zh_TW.utf8, and default setting is en_US.UTF-8

      The Server collation on my SQL Server is Chinese_Taiwan_Stroke_CI_AS.

      I installed Unixodbc and FreeTDS using code
      “sudo apt-get install unixodbc unixodbc-dev tdsodbc freetds-bin”

      Using isql to connect MSSQL server works okay and it didn’t display any garbled code as following picture

      0_1517454994580_004.png

      However, it did not display any Chinese letters in “ “, when I tried to get the same data using Qt(QSqlQuerry). It only displayed English letters as picture.

      0_1517455456896_003.png

      Here is part of the code I used

      QSqlQuery query("SELECT MES_DESC FROM BAS_MES ", db);
      if(query.isActive())
      {
      while(query.next()){
      qDebug() << "Result = " << query.value(0).toString() << endl;
      }

      May I ask how I could solve this issue?
      I need to display Chinese letters in QT.

      Many Thanks in Advance.

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @LeonSu last edited by

        @LeonSu
        https://forum.qt.io/topic/57222/solved-printing-a-string-with-chinese-characters ?

        1 Reply Last reply Reply Quote 0
        • LeonSu
          LeonSu last edited by

          Thanks
          JonB

          I tryed to use the method, but it is not work for me.

          In my Qt, I can display the Chinese letters just using qDebug() as following picture
          0_1517486192381_003.png

          but I don't know what's step wrong , I can't display the Chinese letters from the MSSQL server by Qt;

          1 Reply Last reply Reply Quote 0
          • hskoglund
            hskoglund last edited by

            Hi, just guessing, but in your ~/.freetds.conf file, check that you have

            tds version = 8.0
            client charset = UTF-8
            
            1 Reply Last reply Reply Quote 4
            • First post
              Last post